Event filtering, passing options to month_link?

7 views
Skip to first unread message

Joey

unread,
May 28, 2011, 2:54:12 AM5/28/11
to Event Calendar Plugin
I see that the physical width/height attributes are hard-coded into
the table and div tags, which can make sense, however this allows a
maximum of about 3 events per day with the rest being cut off.

What I'm wondering is if there's a way to filter the events showing on
the calendar to another model's id. I've seen it done with things
like 'current_user', but my situation is a little different:

Example, I have a "Units" model with about 8 units. Seeing as how I
can't fit all 8 units on 1 day, they would each need their own
calendar. So: I pass a link to the calendar with a '?unit=3' param.
While in the controller I can get the calendar to display the events
for the unit, when clicking the links for previous/next month, the
'unit' param goes away.

I tried nesting the calendar resource within my units e.g. '/units/3/
calendar/:year/:month', but the most that gets me is one render where
i can use an :id param, then the month links show up as '/
calendar/:year/:month?id=3'. Finally clicking a month link once more
and the month links drop the '?id=3' param and im back to my normal
calendar.

I may be going about this the wrong way, any suggestions?

Joey

unread,
May 28, 2011, 3:00:55 AM5/28/11
to Event Calendar Plugin
Nevermind, I'm silly. I didn't event notice the 'month_link'
definition in calendar_helper.rb
Hence I am able to use the calendar as a nested resource for my units
with the following using a url such as: '/units/3/
calendar/:year/:month'

def month_link(month_date)
if params[:id]
unit = Unit.find(params[:id])
link_to(I18n.localize(month_date, :format => "%B"),
unit_path(unit) + "/calendar/#{month_date.year}/#{month_date.month}")
# unit calendar
else
link_to(I18n.localize(month_date, :format => "%B"), {:month =>
month_date.month, :year => month_date.year}) # original calendar
end
end

In case it helps anyone else out there some day who is blind like me.
Reply all
Reply to author
Forward
0 new messages