Forum: Ruby on Rails multiple routes to same controller action

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
44999b12bbad1b498252b3ac60c3ab0f?d=identicon&s=25 Maulin pa (mpathare)
on 2009-01-15 05:14
my routes file has the following lines

map.resources :players, :has_many => :matches
map.resources :tourney, :has_many => :matches

now I want to be able to display all the matches played by a player and
also all the matches played in the entire tournament. I have two routes
available

tourney_matches GET  /tourney/:tourney_id/matches
{:controller=>"matches", :action=>"index"}

player_matches GET  /player/:player_id/matches  {:controller=>"matches",
:action=>"index"}

both these paths call the same action in the matches controller, so how
is this supposed to work?
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-01-15 13:36
(Received via mailing list)
You will have to add an "if" on your index action, if there is a
"params[:tourney_id]" load the tourney and then load the matches,
otherwise load the player and the matches.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Thu, Jan 15, 2009 at 1:14 AM, Maulin pa
44999b12bbad1b498252b3ac60c3ab0f?d=identicon&s=25 Maulin pa (mpathare)
on 2009-01-15 15:40
Maurício Linhares wrote:
> You will have to add an "if" on your index action, if there is a
> "params[:tourney_id]" load the tourney and then load the matches,
> otherwise load the player and the matches.
>

Thanks!
This topic is locked and can not be replied to.