Rails Task 3 Nested Routes

I need help with routes. Here are my current routes.

resources :users, :only => [:index, :show, :create, :destroy] do resources :links, :only => [:create, :destroy], :shallow => true, :on => :member end 

and when I run rake routes I get this

  root /(.:format) {:controller=>"users", :action=>"index"} user_links POST /users/:user_id/links(.:format) {:action=>"create", :controller=>"links"} link DELETE /links/:id(.:format) {:action=>"destroy", :controller=>"links"} users GET /users(.:format) {:action=>"index", :controller=>"users"} POST /users(.:format) {:action=>"create", :controller=>"users"} user GET /users/:id(.:format) {:action=>"show", :controller=>"users"} DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"} 

but I try to make my routes the same as I had, but I donโ€™t remember how I got it to work. :(

  root /(.:format) {:controller=>"users", :action=>"index"} user_links POST /users/:user_id/links(.:format) {:action=>"create", :controller=>"users/links"} link DELETE /links/:id(.:format) {:action=>"destroy", :controller=>"users/links"} users GET /users(.:format) {:action=>"index", :controller=>"users"} POST /users(.:format) {:action=>"create", :controller=>"users"} user GET /users/:id(.:format) {:action=>"show", :controller=>"users"} DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"} 

What am I doing wrong? What am I missing?

Edit:

I think that the above does not say very much. The differences in the routes are as follows.

  user_links POST {:action=>"create", :controller=>"links"} link DELETE {:action=>"destroy", :controller=>"links"} user_links POST {:action=>"create", :controller=>"users/links"} link DELETE {:action=>"destroy", :controller=>"users/links"} 

Perhaps this will help a bit.

+3
source share
2 answers

Try it first, remove any options in routes.rb

 resources :users do resources :links, :module => 'users' end 
+1
source

try deleting: shallow => true ... and you should see users / links

see also

http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-shallow-routes

+1
source

All Articles