Providing a nested route to aliases in Rails

If I want to provide an alias for the controller, I can use map.resources :rants, :controller => 'blog_posts'yoursite.com/rants to indicate the subtlety of the controller blog_posts.

How do I specify an alias for a sub-resource, for example, yoursite.com/users/5/rants?

+3
source share
1 answer

You may try:

 map.resources :rants, :controller => 'blog_posts'
 map.resources :users do |users|
   users.resources :rants, :controller => 'blog_posts'
 end

This will give you a URL-address yoursite.com/users/5/rants/you are looking for, and it will generate convenient methods (for example: users_rants_path(@user))

Hope this helps.

+4
source

Source: https://habr.com/ru/post/1706497/


All Articles