我需要一些路線幫助。這是我目前的路線。Rails 3嵌套路線問題
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"}
也許這會有點幫助。
我沒有看到的差異路線?你想用這個完成什麼? –
我想要使用的鏈接資源能夠使用用戶和鏈接控制器。 '':{:action =>「create」,:controller =>「users/links」}'和'{:action =>「destroy」,:controller =>「users/links」}'':'{:action => 「create」,:controller =>「links」}'和'{:action =>「destroy」,:controller =>「links」}' –
請參閱類似問題的答案:http://stackoverflow.com/ a/11849385/317884 –