我正在尝试使用gcal4ruby将事件添加到谷歌日历中。当我运行我的代码时,我得到这个错误:
undefined method `start=' for #<GCal4Ruby::Event:0x00000102bb47b8>下面是我的代码:
service = GCal4Ruby::Service.new
service.authenticate("username", "password")
cal = GCal4Ruby::Calendar.find(service, "calendarname", :first)
event = GCal4Ruby::Event.new(cal)
event.title = "Soccer Game"
event.start = Time.parse("12-06-2009 at 12:30 PM")
event.end = Time.parse("12-06-2009 at 1:30 PM")
event.where = "Merry Playfields"
event.save 错误发生在"event.start = ...“行上。
这让我感到困惑,因为这段代码是从文档中直接复制过来的。
编辑:打开插件的实际.rb文件后,发现文档根本就是错的。方法event.start和event.end应为event.start_time和event.end_time。但是现在我得到了这个错误:
undefined method `editable' for nil:NilClass在"event.save“行。有没有人使用过这个插件,并且对此有所了解?或者可以推荐一个使用google日历的库,它有更好的文档?;-)
发布于 2012-07-11 08:18:11
尝试将事件分配更改为
event = GCal4Ruby::Event.new(service)如果这不起作用,我会做一个gem which gcal4ruby (或者不管gem的名字是什么),并查看那里的代码。因为根据source code,start方法是绝对存在的。
发布于 2012-12-14 03:39:11
实际上,我也遇到了同样的错误。您的编辑和Dty的回答都帮助我弄清楚了这一点。这是我的解决方案。
event = Event.new(service, {
:calendar => cal,
:title => "Event on "+s.start_date.strftime('%D'),
:start_time => s.start_date,
:end_time => s.end_date,
:where => "www.example.com"})
event.savehttps://stackoverflow.com/questions/11423747
复制相似问题