Hi all, lets say i have the following relationship:
class Event < ActiveRecord::Base
has_many :tickets
end
class Ticket < ActiveRecord::Base
belongs_to :event
end
And I have a route like this:
map.resources :events, :has_many => :tickets
map.resources :tickets
And i have a before filter like this on tickets_controller:
before_filter :get_event
def get_event
@event = Event.find(params[:event_id])
end
And I have an index action on tickets_controller like this:
if @event == nil
@tickets = Ticket.all
else
@tickets = @event.tickets.all
end
how come if I go to /tickets (where no event instance is passed) it says I still need an event id?
I am trying to keep DRY otherwise i would separate the index action into to actions and exclude one in the before filter.
appreciate the help!