excid3 / simple_calendar

A wonderfully simple calendar gem for Rails
http://excid3.github.io/simple_calendar
MIT License
1.58k stars 268 forks source link

problem when trying to connect to google calendar #198

Closed Jiaxinl7 closed 4 years ago

Jiaxinl7 commented 6 years ago

Hi When I try to set google calendar's start.date_time as the attribute of month_calendar:

<%= month_calendar events: @event_list.items, attribute: :start.date_time do |date, events| %>
  <%= date.strftime("%d") %>

  <% events.each do |event| %>
    <div>
      <%= event.summary %>
    </div>
  <% end %>
<% end %>

There is NoMethodError: undefined method `date_time' for :start:Symbol

But when I try to set non-nested ones, like updated, as the attribute: attribute: :updated It worked well. BTW, when I render the event.start.date_time directly in the same page, it looks all right. I just can't set it as the attribute successfully. How could I solve this problem? Thank you!

Gloria

excid3 commented 6 years ago

Hey @midnight-blue

When you passed in the attribute, you need to just give it a single symbol. This isn't valid Ruby syntax: attribute: :start.date_time because you can't have a period in the symbol of :start.date_time.

If your column is called date_time then you would just use attribute: :date_time.

If you have this nested in like a json column or something, you'll want to just add a method that can access it, rather than having to call event.start.date_time. I would add a start_time method that would call the start.date_time on your event in that case.