2012-08-31 37 views
0

我嘗試創建一個部分與我的車型之一的更新形式,但是當我運行服務器,並與部分瀏覽的頁面,我得到一個奇怪的例外:回報率:不能更新模型

NoMethodError in Simpadmin/transactions#index 

Showing /home/ben/proj/Simplee/master/app/views/simpadmin/transactions/_transaction_actions.html.haml where line #17 raised: 

undefined method `payments_transaction_path' for #<#<Class:0x00000007bf1768>:0x00000007bceb00> 
Extracted source (around line #17): 

14: %span.refund-success= flash[:refund_success] 
15: 
16: .refund-edit 
17: = form_for transaction do |refund_form| 
18:  .refund-reason 
19:  = refund_form.label(:refund_reason, "Reason for refund:") 
20:  = select_tag(:refund_reason, options_for_select(possible_refund_emails), :class => 'refund-reason-select') 
Trace of template inclusion: app/views/simpadmin/transactions/_ 

item.html.haml, app/views/simpadmin/transactions/index.html.haml 

或許真的是錯了我擊潰(?) 我應該改變部分本身的東西?

編輯:路線不是由我寫的。無論如何,這裏是交易的路線部分:

resources :transactions, :only => [:index, :update, :show] do               
155  collection do                          
156   get :export                          
157   post :edit_cashed_checks                       
158   put :update_cashed_checks                       
159  end                             
160  member do                           
161   match :update_payee, :via => [:post, :put]                  
162   match :add_comment, :via => :post                     
163   put :refund                          
164  end                             
165  end  
+0

讓知道路線文件內容請... –

+0

問題與路由,確保 –

+0

作爲Sush說,路線現在會有所幫助。而且,最好知道'transaction'對象是什麼類。我懷疑'PaymentTransaction'。 –

回答

1

當你正在使用的form_for並通過一些模型的對象,在這種情況下軌隱含假設行動,使用輔助函數被調用。 Rails使用xyzs_path幫助找出匹配的路由,其中​​XYZ是型號名稱,其對象,我們傳遞給的form_for。這意味着應該有你的情況

resources :xyzs 

匹配命名的路由

match 'some_url' => 'some_controller#action', :as => 'xyzs' 

,你需要定義

resources :payments_transaction 

命名的路由

match 'some_url' => 'some_controller#action', :as => 'payments_transaction' 
+0

,你應該使用 命名空間:支付做 資源:交易 結束 –

+0

高興,它幫助:),其實我一直在尋找爲此,但你的問題驅使我朝着解決方案。 –

1

您尚未定義此表單的路由。你必須在你的路由文件中定義它是這樣的:

resources :payments do 
    resources :transactions 
end 

欲瞭解更多信息,請參見Routing Guide

+0

我剛纔編輯我的問題,並增加了部分航線可能 – benams