2011-05-08 47 views
1

在我的Rails應用程序有一個部分,它包含了新的編輯動作之間共享的形式:命名空間爲什麼form_for爲名稱空間控制器使用不正確的REST url_helpers?

<%= form_for @customer do |f| %> 

.... 

<% end %> 

這些行動是一個控制器(稱爲客戶)(稱爲管理),如果嘗試運行該代碼顯示的錯誤執行時的form_for:

<%= form_for :customer, @customer do |f| %>

.... 

<% end %> 

undefined method `customer_path'

有這個使用解決

現在的形式與正確的URL生成時被行動稱爲而是編輯時產生的形式的網址爲「/管理/用戶/ 1/編輯」,而不是更新。如果提交表單顯示錯誤:

No route matches "/admin/customers/1/edit"

但在routes.rb中有:

namespace :admin do

resources :customers

end

和耙:路線顯示所有的REST網址:

admin_customers GET /admin/customers(.:format) {:action=>"index", :controller=>"admin/customers"} POST /admin/customers(.:format) {:action=>"create", :controller=>"admin/customers"} new_admin_customer GET /admin/customers/new(.:format) {:action=>"new", :controller=>"admin/customers"} edit_admin_customer GET/admin/customers/:id/edit(.:format){:action=>"edit",:controller=>"admin/customers"} admin_customer GET /admin/customers/:id(.:format) {:action=>"show",:controller=>"admin/customers"} PUT /admin/customers/:id(.:format) {:action=>"update", :controller=>"admin/customers"} DELETE /admin/customers/:id(.:format) {:action=>"destroy",:controller=>"admin/customers"}

任何想法?

回答

3

試試這個

<%= form_for [:admin, @customer] do |f| %> 
+0

生成的表單操作是「/管理/用戶/ 1」,如果提交返回索引頁沒有任何變化記錄。 – byterussian 2011-05-08 13:16:07

+0

其實是正確的行爲。你期望什麼?如果沒有任何變化 - 控制器代碼 – fl00r 2011-05-08 13:19:26

+0

Ops中存在問題,對不起,更新方法中的邏輯錯誤現在可用。謝謝。 – byterussian 2011-05-08 13:20:01

相關問題