undefined方法`start ='gcal4ruby

时间:2012-07-11 00:03:25

标签: ruby-on-rails google-calendar-api

我正在尝试使用gcal4ruby将事件添加到Google日历中。当我运行我的代码时,我收到此错误:

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”行。有人使用这个插件并有线索吗?或者可以建议使用具有更好文档的谷歌日历的库? ; - )

2 个答案:

答案 0 :(得分:2)

我实际上遇到了同样的错误。你的编辑和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.save

答案 1 :(得分:1)

尝试将事件分配更改为

event = GCal4Ruby::Event.new(service)

如果这不起作用,我会做一个gem which gcal4ruby(或者宝石的名字)并查看那里的代码。因为根据source codestart方法肯定存在。