我想在單個視圖中使用批量更新每個操作,只需一個更新按鈕。使用這個下面的代碼,Rails的thows這個錯誤Rails 3:大量更新
Showing /home/vincent/git/gestion/app/views/operations/tag.html.erb where line #23 raised:
undefined method `merge' for 1:Fixnum
Extracted source (around line #23):
20: <td>
21: <% @tags.each do |elem| %>
22: <%= f.label elem.tag %>
23: <%= f.check_box "operation[tag_ids][]", elem.id, operation.tags.include?(elem) %>
24: <% end %>
25: </td>
26: <td><%= f.submit %></td>
模型
class Operation < ActiveRecord::Base
attr_accessible :credit, :date_operation, :debit, :libelle, :tag_ids
has_and_belongs_to_many :tags
accepts_nested_attributes_for :tags, :allow_destroy=>true
end
class Tag < ActiveRecord::Base
attr_accessible :id, :tag
has_and_belongs_to_many :operations
end
控制器
def tag
@operations = Operation.limit(100)
@tags = Tag.all
respond_to do |format|
format.html { "tag" }# tag.html.erb
# format.json { render json: @operations }
end
end
查看
<% @operations.each do |operation| %>
<tr>
<td><%= operation.date_operation %></td>
<td><%= operation.libelle %></td>
<td><%= operation.credit %></td>
<td><%= operation.debit %></td>
<%= form_for operation do |f| %>
<td>
<% @tags.each do |elem| %>
<%= f.label elem.tag %>
<%= f.check_box "operation[tag_ids][]", elem.id, operation.tags.include?(elem) %>
<% end %>
</td>
<td><%= f.submit %></td>
<% end %>
</tr>
<% end %>
你有關於這個問題的任何線索/幫助?
預先感謝您
編輯1:將完整的堆棧跟蹤
可能有助於如果包括從錯誤中完全堆棧跟蹤;它會顯示觸發錯誤的行。 – 2013-03-17 23:58:33
謝謝你的回答。我已經添加了堆棧跟蹤來幫助你。 – Turambar37 2013-03-18 19:14:10
更改'check_box_tag'的'f.check_box' – fmendez 2013-03-18 19:18:55