我需要一些路线帮助。这是我目前的路线。
resources :users, :only => [:index, :show, :create, :destroy] do
resources :links, :only => [:create, :destroy], :shallow => true, :on => :member
end
当我运行rake路线时,我得到了这个
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"}
但是我想让我的路线成为这样,这就是我所拥有的,但我不记得我是如何让它工作的。 :(
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"}
我做错了什么?我错过了什么?
编辑:
我猜上面并没有多说。路线的差异是这样的。
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"}
也许这会有所帮助。
答案 0 :(得分:1)
首先尝试,删除routes.rb中的所有选项
resources :users do
resources :links, :module => 'users'
end
答案 1 :(得分:1)
尝试删除:shallow =>是的......你应该看到用户/链接
另见
http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-shallow-routes