Say I have a child model with two parent models:
Event has_many tickets
Person has_many tickets
Ticket belongs_to Event
Ticket belongs_to Person
Routes are mapped so Ticket always nests within Event or Person:
resource :people do
resources :tickets
end
resources :events do
resources :tickets
end
How do I scope my ticket_Controller CRUD actions by the parent resource?
Right now I'm testing for params and using conditional statements:
class TicketController
before_filter :get_person
before_filter :get_event
def index
if @person do
...
elsif @event do
...
end
respond_to
...
end
end
That seems a bit tedious to do for every action. Is there a more rails-y DRY way to do it?