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    
4

2 回答 2

1

当您使用 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'  
于 2012-09-02T19:01:45.193 回答
1

您尚未定义此表单的路线。你必须在你的路由文件中这样定义它:

resources :payments do
  resources :transactions
end

有关详细信息,请参阅路由指南

于 2012-08-31T19:40:32.027 回答