虚拟属性,参数数量错误

时间:2013-07-23 08:25:05

标签: ruby-on-rails ruby-on-rails-3

我尝试为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> 

我需要改变什么?

1 个答案:

答案 0 :(得分:1)

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

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