1

単一の更新ボタンを使用して、単一のビューですべての操作を一括更新する必要があります。次のコードを使用して、Railsはこのエラーを処理します

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:フルスタックトレースを追加

4

2 に答える 2

0

たとえば、f.check_boxforを変更する必要があります。check_box_tag

<%= check_box_tag "operation[tag_ids][]", elem.id, operation.tags.include?(elem) %>

このシナリオの問題はf.check_box、値がこの場合ではない形式にバインドされることを期待していることです。

于 2013-03-18T19:24:37.877 に答える
0

この場合はnested_formgemを使用してください。うまくいくと思います。

nested_formの詳細については、ここをクリックしてください

于 2013-03-18T23:24:03.343 に答える