0

我试图为 ebm 设置一个虚拟属性:

<%= form_for Ebm.new do |f| %>
<td> <%= f.text_field :ebm_findid %></td> 
......

在我的 ebm 模型中:

class Ebm < ActiveRecord::Base
attr_accessible :content, :extra, :number, :text

def ebm_findid(name)
  self.ebm_id = Ebm.find_by_name(name)
end
end

但不知何故我得到了错误:

ArgumentError in Categories#index

Showing C:/Sites/ruble21.07abends/app/views/ebms/_favorite.html.erb where line #21 raised:

wrong number of arguments (0 for 1)
Extracted source (around line #21):

18: <% end %>
19: <tr>
20: <%= form_for Ebm.new do |f| %>
21:     <td> <%= f.text_field :ebm_findid %></td> 

我必须改变什么?

4

1 回答 1

1

要修复NoMethodError in EbmsController#create undefined method 'find_by_name'错误:

find_by_name期望Ebm有属性name。确保你拥有它。

于 2013-07-23T08:36:02.507 回答