我尝试为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>
我需要改变什么?
答案 0 :(得分:1)
修复NoMethodError in EbmsController#create undefined method 'find_by_name'
错误:
find_by_name
期望Ebm
具有属性name
。确保你拥有它。