Routing Rails 管理控制器创建操作
除创建记录外,专用的 admin/countries_controller 已正确用于所有操作(索引等)。这里父控制器目录中的常规country_controller处于活动状态:
Started POST "/countries" for 127.0.0.1 at 2011-06-29 23:26:38 +0200
Processing by CountriesController#create as HTML
将POST操作路由到admin/countries缺少什么?
routes.rb:
resources :countries
namespace :admin do
resources :countries
end
rake 路线:
countries GET /countries(.:format) {:action=>"index", :controller=>"countries"}
POST /countries(.:format) {:action=>"create", :controller=>"countries"}
new_country GET /countries/new(.:format) {:action=>"new", :controller=>"countries"}
admin_countries GET /admin/countries(.:format) {:action=>"index", :controller=>"admin/countries"}
POST /admin/countries(.:format) {:action=>"create", :controller=>"admin/countries"}
new_admin_country GET /admin/countries/new(.:format) {:action=>"new", :controller=>"admin/countries"}
此处未回答类似问题: Rails 帮助构建管理区域 - 路由问题
A dedicated admin/countries_controller is being correctly used for all actions (index, ...), except for creating records. Here the regular countries_controller from the parent controller directory is active:
Started POST "/countries" for 127.0.0.1 at 2011-06-29 23:26:38 +0200
Processing by CountriesController#create as HTML
What is missing to have the POST action being routed to admin/countries?
routes.rb:
resources :countries
namespace :admin do
resources :countries
end
rake routes:
countries GET /countries(.:format) {:action=>"index", :controller=>"countries"}
POST /countries(.:format) {:action=>"create", :controller=>"countries"}
new_country GET /countries/new(.:format) {:action=>"new", :controller=>"countries"}
admin_countries GET /admin/countries(.:format) {:action=>"index", :controller=>"admin/countries"}
POST /admin/countries(.:format) {:action=>"create", :controller=>"admin/countries"}
new_admin_country GET /admin/countries/new(.:format) {:action=>"new", :controller=>"admin/countries"}
Similar question unanswered here:
Rails help with building Admin area - Routing problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
form_for
也需要命名空间:当您将
@country
传递给form_for
时,它不会知道您希望此表单进入哪个命名空间因此它将默认为标准的POST /countries
URL。Your
form_for
needs to be namespaced too:When you pass
@country
toform_for
it's not going to know what namespace you want this form to go to and so it will default to just the standardPOST /countries
URL.