Reputation: 159
I am trying to get simple_calendar gem to work in my rails application. but keep getting an "undefined method `has_key?' for nil:NilClass"
Running Rails 5.0.0
Gemfile -> gem "simple_calendar", "~> 2.0"
Ran "bundle install" command, restarted application
Screenshot of error --> https://i.sstatic.net/d0K3J.jpg
Pastebin of controller and view page -> http://pastebin.com/8WX4dZNs
Thanks in advance!
Upvotes: 0
Views: 1730
Reputation:
I think you need to add the start_time alias definition inside the model you use for your events, here I have this inside my app/models/evento.rb
def start_time
self.fecha
end
Here 'fecha' is the start date for my event. Then you have to manipulate your events as Carlos Ramirez explains, so you have to have something like this inside your 'calendar.html.erb':
<h3>Eventos (<%= @eventos.count %>)</h3>
<%= month_calendar events: @eventos do |date, eventos| %>
<%= date.day %>
<% eventos.each do |evento| %>
<div>
<%= link_to evento.title, evento %>
</div>
<% end %>
<% end %>
That should render the link to your event.
Upvotes: 1
Reputation: 159
Copied files from https://github.com/excid3/simple_calendar/tree/master/lib directory into my applications lib directory
edited my calendar.html.erb file
<%= month_calendar do |date| %>
<%= date %>
<% end %>
Restarted server and got a calendar displaying
Upvotes: 0
Reputation: 7434
As per the documentation, the calendar
helper takes a parameter which is a Hash
. In your code snippet you've passed in a collection of events (@events
), not a Hash
of options.
If you want to pass the events in, the documentation shows how to do it.
<%= month_calendar events: @meetings do |date, meetings| %>
<%= date %>
<% meetings.each do |meeting| %>
<div>
<%= meeting.name %>
</div>
<% end %>
<% end %>
Source: https://github.com/excid3/simple_calendar#rendering-events
So in your case, you'll want to pass your @events
collection in as a key value pair like so: <%= calendar events: @events do %>
.
Upvotes: 1