simple_calendar icon indicating copy to clipboard operation
simple_calendar copied to clipboard

How to use :start_date_param correctly?

Open aarona opened this issue 2 years ago • 1 comments

Not sure if what I'm trying to do is actually the feature I need and I'm using it incorrectly, or if there's a bug that needs to get fixed.

I have an Event model that uses starts_at as its starting time param. I'm getting the following render error:

undefined method `start_time' for #<Event:0x00007f37d9235588>
Did you mean?  starts_at

And it's failing on:

month_calendar(events: @calendar_events, start_date_param: :starts_at) do |day, events|

From what I gathered from your documentation, I can use the :start_date_param to override the default starting parameter (which I think is why its expecting my model to respond to start_time).

The workaround is to just add a start_time method to my Event class and have it return starts_at.

Am I doing something wrong here or is the start_date_param option used for something else?

aarona avatar Oct 08 '21 01:10 aarona

Hi, start_date_param refers only to the url parameter that is used to indicate the current date of the calendar.

In order to let the calendar use a different function to access the starting date, you can use the attribute option in the view helper. That would look like this in your example

<% month_calendar(events: @calendar_events, attribute: :starts_at) do |day, events| %>
   <!-- render your view -->
<% end %>

1klap avatar Nov 14 '21 21:11 1klap