Cam*_*ike 8 routes ruby-on-rails ruby-on-rails-3
在rails 2.x中,我使用了浅层路由,但这似乎从rails 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
Run Code Online (Sandbox Code Playgroud)
缺少使用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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5961 次 |
| 最近记录: |