gpt4 book ai didi

ruby-on-rails-3 - Rails 3 嵌套路由问题

转载 作者:行者123 更新时间:2023-12-02 02:23:05 24 4
gpt4 key购买 nike

我需要一些路线方面的帮助。这是我当前的路线。

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

当我运行 rake routes 时,我得到了这个

  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"}

也许这会有所帮助。

最佳答案

尝试删除 :shallow => true ... 你应该会看到用户/链接

另见

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

关于ruby-on-rails-3 - Rails 3 嵌套路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7225248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com