I’ve got an application that uses a calendar, and I’d like to provide a calendar summary on login. The summary should be formatted so it shows events for Today, Tomorrow, and This Week, like this:
Events For:
Today
- Event 1
Tomorrow
- Event 2
- Event 3
- Event 4
This Week
- Event 5
- Event 6
- Event 7
- Event 8
How do I render the partials so that they are grouped together in the right way, based on their date?
First one could add a model method for_dates(start_date,end_date) which would contain:
where([:date_column >= ? and :date_column <= ?, start_date, end_date])Then use:
Model.for_dates(Date.today, Date.today)Model.for_dates(Date.today+1, Date.today+1)Default ‘week’ is Sunday to Monday. Add an offset if you wish different days, e.g.
Monday to Friday is
Model.for_dates(Date.today.beginning_of_week+1, Date.today.end_of_week+1)