2011-06-29 79 views
0

專門的admin/countries_controller正在正確使用所有操作(index,...),除了創建記錄。這裏從父目錄控制器定期countries_controller活躍:路由導軌管理員控制器創建操作

Started POST "/countries" for 127.0.0.1 at 2011-06-29 23:26:38 +0200 
    Processing by CountriesController#create as HTML 

缺什麼有POST操作被路由到管理/國家

的routes.rb:

resources :countries 

    namespace :admin do 
    resources :countries 
    end 

耙路線:

 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 help with building Admin area - Routing problem

+0

你是如何構建在你的視圖中啓動POST請求的url的? – drummondj

+0

'<%= link_to'New Country',new_admin_country_path%>'會產生標準的scaffold form helper,包含'<%= form_for(@country)do | f | %>'和'<%= f.submit%>' – David

回答

1

form_for需要過於命名空間:

<%= form_for [:admin, @country] do |f| %> 
    ... 
<% end %> 

當你傳遞@countryform_for它不會知道你想要這種形式去什麼命名空間,所以它會默認爲只是標準POST /countries URL。

+0

不錯,謝謝瑞恩! – David

相關問題