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

Set view based on first event date #218

Closed drelich closed 5 years ago

drelich commented 5 years ago

Hi,

First of all, thanks for this gem! It saved me a lot of headaches :)

Now, I know the calendar renders current month by default and there is an option to set it to whatever month I need. I was just wondering is there a simple way to render the month based on when the first event is on?

I thought about getting that first event record, get the date and then use it as the start_date parameter but maybe you're way ahead and added some sort of a much simpler approach?

Thanks.

excid3 commented 5 years ago

No option for that built-in, but you can simply do that by finding the first event and then use the option to set the month.

# Sort events, then grab the first one and convert it to a date
params[:start_date] = @events.order(created_at: :asc).first.start_time.to_date
drelich commented 5 years ago

Awesome! Thanks so much for a quick response and a hint at how to go about it :)

Cheers.