ruby-on-rails – Rails 3,浅路线
发布时间:2020-12-16 19:12:17 所属栏目:百科 来源:网络整理
导读:在rails 2.x中,我使用浅路线,但这似乎从轨道3中缺失(至少在API http://apidock.com/rails/ActionController/Resources/resources中). 当我在rails 3中传递此选项时,它不会抛出任何错误,但我也没有得到我期望的所有路径. Rails 3 routes.rb resources :users,
在rails 2.x中,我使用浅路线,但这似乎从轨道3中缺失(至少在API
http://apidock.com/rails/ActionController/Resources/resources中).
当我在rails 3中传递此选项时,它不会抛出任何错误,但我也没有得到我期望的所有路径. Rails 3 routes.rb resources :users,:shallow=>true do resources :recipe do resources :categories do resources :sections do resources :details do end end end end end 缺少使用rails 2.x等效生成的路由(只是配方资源的示例): 获取new_recipe(我只有new_user_recipe),和 POST食谱(创建新食谱,我只有POST user_recipe) 有意义的是,这些路由不会被生成,但是我的旧代码通过在每种形式中传递user_id来解决它(不太优雅,同意). 问题是:轨道3中是否存在“浅层”路线的文档?有没有办法生成我在rails 2.x中缺少的路由? 谢谢, 解决方法
您需要将:shallow选项应用于嵌套资源.这应该给你你想要的:
resources :users do resources :recipe,:shallow=>true do resources :categories do resources :sections do resources :details do end end end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |