簡體   English   中英

RoR:無法更新模型

[英]RoR: can't update a model

我嘗試使用其中一個模型的更新表單創建一個部分,但是當我運行服務器並使用部分瀏覽頁面時,我得到一個奇怪的異常:

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    

您尚未定義此表單的路由。 您必須在路由文件中將其定義為:

resources :payments do
  resources :transactions
end

有關詳細信息,請參閱“ 路由指南”

當您使用某些模型的form_for和傳遞對象時,在這種情況下,rails隱式假設使用幫助程序例程調用該操作。 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'  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM