match ‘ackord/:artist_id/:id’ => ‘songs#show’, :as => :song
resources :artists, :path => “ackord” do
resources :songs
end
Which makes it work without the /songs/ part in the url at least for
the show action. It still works with the /song/ part though, which I
don’t want. Duplicate urls are not good
Also, I have to create a match for each action with this approach. Is
there a better way to do this?
Excerpts from Linus P.'s message of Mon Mar 21 03:40:43 -0700
2011:
Which makes it work without the /songs/ part in the url at least for
the show action. It still works with the /song/ part though, which I
don’t want. Duplicate urls are not good
Also, I have to create a match for each action with this approach. Is
there a better way to do this?
config/routes.rb
resources :artists, :path => ‘ackord’ do
resources :songs, :path => ‘’
end
rake routes
artist_song GET /ackord/:artist_id/:id(.:format)
{:action=>“show”, :controller=>“songs”}
When I go to …/ackord/artist-name I want to load the artists show
action and inside this I loop out all the songs that’s related to the
artist.
When I go to this url now it load the songs index action instead. Its
because I have these two in my routes
artist_songs GET /ackord/:artist_id(.:format)
{:action=>“index”, :controller=>“songs”}
and
artist GET /ackord/:id(.:format)
{:action=>“show”, :controller=>“artists”}
Perhaps this is actually better and instead of showing the songs
inside artist#show I filter the songs and show them in songs#index
instead.
Any suggestions on either approach? Would it even matter?
Excerpts from Linus P.'s message of Mon Mar 21 08:37:33 -0700
2011:
artist_songs GET /ackord/:artist_id(.:format)
{:action=>“index”, :controller=>“songs”}
and
artist GET /ackord/:id(.:format)
{:action=>“show”, :controller=>“artists”}
Perhaps this is actually better and instead of showing the songs
inside artist#show I filter the songs and show them in songs#index
instead.
Personally I think it’s fine for this logic to live in the songs
controller,
especially given that you’ve effectively namespaced the songs (by
artist) by
making it a nested resource.
That said, there is a bit of an ugliness in the route collision,
especially
since rails presumably doesn’t guarantee the how the collision is
resolved.
OTOH there’s a lot of ugliness in having to specify each route manually.
Unless
someone else on the list has a better suggestion than the one I offered,
you may
have to simply pick your poison.
–
med vnlig hlsning
David J. Hamilton
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.