Skip to content

Display events for an individual user

jeffschuil edited this page Apr 16, 2011 · 2 revisions

Displaying events for an individual user, rather than all events is pretty simple.

First let's assume you've created a user model, declared declared has_many :events, and added a user_id column to your event table.

  class User < ActiveRecord::Base
    has_many :events
  end

  class Event < ActiveRecord::Base
    has_event_calendar
    belongs_to :user
  end

Then all you need to do is modify the call for @event_strips (the default example sets this in the CalendarController).

  # assuming, in this case, current_user is set in a before_filter
  @event_strips = current_user.events.event_strips_for_month(@shown_month)

This was a very simple case, but you should be able to modify for your needs.

Remember, you can also pass in additional conditions for finding events if needed.

  @event_strips = Event.event_strips_for_month(@shown_month, :include => :some_relation, :conditions => 'some_relations.some_column = true')