I have an event model that has two namespaces:
class Event < ActiveRecord::Base
scope :future, lambda { where('events.date >= ?', Time.zone.now) }
scope :past, lambda { where('events.date <= ?', Time.zone.now) }
end
I call these areas from my controller, creating two new controller actions (called "future" and "past"):
My controller:
class EventsController < InheritedResources::Base
actions :index, :show, :future, :past
has_scope :future
has_scope :past
def future
index! { @events = Event.future }
end
def past
index! { @events = Event.past }
end
end
I also have views and routes for these additional activities.
It works great. My application does what I want, and I can refer to the new actions in the sidebar as follows:
%li
= link_to 'Events Home', events_path
%li
= link_to 'Future Events', future_events_path
%li
= link_to 'Past Events' past_events_path
, , , , , . , . , , , . , , .
, "" "" :
%li
= link_to 'Events Home', events_path
%li
= link_to 'Future Events', events_path.future
%li
= link_to 'Past Events' events_path.past
, . , select_tag, , JS...