Skip to content

Display events of different ruby class types

jeffschuil edited this page Mar 9, 2011 · 1 revision

Here's a simple way to show events on the calendar whose underlying ruby classes may be of different types.

For instance, you might have an event model, as well as a game model. In both event.rb and game.rb make sure you've declared:

  has_event_calendar

Then in your calendar_controller.rb, get the start and end dates, the events and games for those dates, and create your event_strips for the two.

  start_d, end_d = Event.get_start_and_end_dates(@shown_month, @first_day_of_week)
  @events = Event.events_for_date_range(start_d, end_d)
  @games = Game.events_for_date_range(start_d, end_d)
  @event_strips = Event.create_event_strips(start_d, end_d, @events + @games)

Finally, in your calendar_helper.rb make use of polymorphic_path to link to the individual 'events'.

  link_to(event.name, polymorphic_path(event), :title => event.name)