How to configure nested routers to omit controller from URL?

I have the following nested route in my routes.rb

map.resources :users do |user|
user.resources :pie_charts
end

and the ‘rake routes’ command shows the following routes:

user_pie_charts GET /users/:user_id/pie_charts(.:format)
{:controller=>“pie_charts”, :action=>“index”}
user_pie_chart GET /users/:user_id/pie_charts/:id(.:format)
{:controller=>“pie_charts”, :action=>“show”}

This all works, but I want the URLs to omit “/users,” that is:

user_pie_charts GET /:user_id/pie_charts(.:format)
user_pie_chart GET /:user_id/pie_charts/:id(.:format)

Is this possible, and if so how would one go about configuring it?

  • Steve W.

Hi,

I have the same problem but I need to omit both users and pie_charts
from url… and my pie_charts has many others nested resources.

If someone know how to do it, please, tell us.

With regards
Petr Blaho

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs