1

A simple question. I'm wondering what the proper way to do this is. Say you have this:

Event
Venue.has_many :events
Performer.has_many :events

And for routing:

resources :venues do
  resources :events
end

resources :performers do
  resources :events
end

And you are in events/index.html.haml. What is the proper way to link to an internal action?


Option 1

= link_to "New event", {:action => :new}

Option 2

Using a named route like?

= link_to "New event", params[:performer_id] ? new_performer_event_path(params[:performer_id) : new_venue_event_path(params[:venue_id])

Option 3 or do you use a shallow route?

= link_to "New event", new_event_path

Just curious what the proper / industry standard way of doing this is. Isn't option 2 bad practice in general?

Thanks for your help.

Binary Logic
  • 1,529
  • 2
  • 17
  • 19

2 Answers2

0

Do you really need nested resources :events?

If so, you could use
= link_to "New event", [@parent, @event] in events/index.html.haml
and

def index  
  @parent = Performer.find_by_id(params[:performer_id]) || Venue.find_by_id(params[:venue_id])  
  @event = Event.new  
end
Sergey Alekseev
  • 11,910
  • 11
  • 38
  • 53
0

It depends on how you want your url to be. if you want it to be

/performers/:performer_id/events/new

then go for

new_performer_event_path(params[:performer_id)
usha
  • 28,973
  • 5
  • 72
  • 93