Hi!
I have two models, artists and songs.
I have this in my route file:
resources :artists, :path => "ackord" do
resources :songs
end
Which gives me urls like this (I''m using
https://github.com/norman/friendly_id
to create and manage slugs):
example.com/ackord/artistname/songs/songname-id
Now I want to remove the /songs part to get a url like this:
example.com/ackord/artistname/songname-id
Is it possible? I have tried to do it with match without success.
Any ideas?
Best Regards
Linus
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Any ideas anyone?
I tried this:
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?
Best Regards
Linus
On 19 mar, 23:51, Linus Pettersson
<linus.petters...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi!
>
> I have two models, artists and songs.
>
> I have this in my route file:
> resources :artists, :path => "ackord" do
> resources :songs
> end
>
> Which gives me urls like this (I''m
usinghttps://github.com/norman/friendly_id
> to create and manage slugs):
> example.com/ackord/artistname/songs/songname-id
>
> Now I want to remove the /songs part to get a url like this:
> example.com/ackord/artistname/songname-id
>
> Is it possible? I have tried to do it with match without success.
>
> Any ideas?
>
> Best Regards
> Linus
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Excerpts from Linus Pettersson''s message of Mon Mar 21 03:40:43 -0700 2011:> Any ideas anyone? > > I tried this: > > 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?# 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"} Does this work for you Linus? -- med vänlig hälsning David J. Hamilton -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi and thank you for your reply!
It kinda works... There is some issues though.
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? :)
Best Regards
Linus
On 21 mar, 15:49, David J. Hamilton
<gro...-RNpBDse/2JlBDgjK7y7TUQ@public.gmane.org>
wrote:> Excerpts from Linus Pettersson''s message of Mon Mar 21 03:40:43
-0700 2011:
>
>
>
>
>
>
>
>
>
> > Any ideas anyone?
>
> > I tried this:
>
> > 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?
>
> # 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"}
>
> Does this work for you Linus?
> --
> med vänlig hälsning
> David J. Hamilton
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Excerpts from Linus Pettersson''s message of Mon Mar 21 08:37:33 -0700 2011:> Hi and thank you for your reply! > > It kinda works... There is some issues though. > > 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.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 vänlig hälsning David J. Hamilton -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you. I''ll keep it like this for now :) Anyone else has any thoughts in this matter? Best Regards Linus On 21 mar, 16:57, David J. Hamilton <gro...-RNpBDse/2JlBDgjK7y7TUQ@public.gmane.org> wrote:> Excerpts from Linus Pettersson''s message of Mon Mar 21 08:37:33 -0700 2011: > > > > > > > > > > > Hi and thank you for your reply! > > > It kinda works... There is some issues though. > > > 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. > > 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 vänlig hälsning > David J. Hamilton-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.