本文介绍了在 rail3 上编写嵌套的命名空间路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用
rails g scaffold_controller admin/sub/Product name:string
生成crud页面,
现在我需要写route.rb文件来映射admin_sub_product_controller,如何在rails3上写这个路由文件?
now i need write route.rb file to map the admin_sub_product_controller,how to write this route file on rails3?
我很难写出 2 级命名空间映射路由
it's hard for me to write 2 level namespace mapping route
namespace admin do
resource :products
end
这个只针对/admin/products,但是映射admin/sub/proudcts怎么写?
this only wokrs for /admin/products,but for mapping admin/sub/proudcts how to write?
推荐答案
namespace :admin do
namespace :sub do
resources :products
end
end
耙路线
admin_sub_products GET /admin/sub/products(.:format) {:action=>"index", :controller=>"admin/sub/products"}
POST /admin/sub/products(.:format) {:action=>"create", :controller=>"admin/sub/products"}
new_admin_sub_product GET /admin/sub/products/new(.:format) {:action=>"new", :controller=>"admin/sub/products"}
edit_admin_sub_product GET /admin/sub/products/:id/edit(.:format) {:action=>"edit", :controller=>"admin/sub/products"}
admin_sub_product GET /admin/sub/products/:id(.:format) {:action=>"show", :controller=>"admin/sub/products"}
PUT /admin/sub/products/:id(.:format) {:action=>"update", :controller=>"admin/sub/products"}
DELETE /admin/sub/products/:id(.:format) {:action=>"destroy", :controller=>"admin/sub/products"}
这篇关于在 rail3 上编写嵌套的命名空间路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!