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

undefined method `reject' for nil:NilClass #322

Closed 800a7b32 closed 1 year ago

800a7b32 commented 1 year ago

when trying to load a calendar where the list of events is blank, an exception gets raised (tested against simple_calendar 2.4.3...v3.0.1)

undefined methodreject' for nil:NilClass`

Example calendar view:

<div class="bg-white rounded-lg shadow overflow-hidden border-t">
  <%= week_calendar(attribute: :starts_at, events: @upcoming_appointment_slots) do |date, events| %>
    <% events.each do |event| %>
      <% if event.starts_at.to_time.after?(Time.current) && event.available? %>
        <%= link_to "#{event.starts_at.to_time.strftime("%H:%M")} to #{event.ends_at.to_time.strftime("%H:%M")}", book_appointment_public_appointment_calendar_path(starts_at: event.starts_at.to_time, ends_at: event.ends_at.to_time), class: "w-full flex justify-center py-3 px-4 border border-transparent rounded-md shadow-sm text-lg font-medium text-white bg-green-500 hover:bg-green-600 hover:text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-400 my-3", data: {turbo: false} %>
      <% end %>
    <% end %>
  <% end %>
</div>
excid3 commented 1 year ago

Please provide a full stacktrace.

800a7b32 commented 1 year ago

@excid3 here you go https://gist.github.com/800a7b32/89f89aeac71eb49155d1b70b085628b5

excid3 commented 1 year ago

Looks like you're passing @upcoming_appointment_slots as nil but it needs to be an array?

800a7b32 commented 1 year ago

legend! yep there are some instances where there were not upcoming appointment slots, hence nil being returned.