У меня есть 3 модели, Продукт, Вариация и Цвет.Я использую гем nested_form.
Product has_many :variations
Variation belongs_to :product
Variation has_and_belongs_to_many :colors
Color has_and_belongs_to_many :variations
Через форму продукта у меня есть nested_form для вариантов.Я хочу связать цвета с помощью флажка, но получаю undefined local variable or method "color_ids"
Модель продукта
def new
@product = Product.new
1.times { @product.variations.build }
end
def create
@product = Product.new(params[:product])
...
end
Моя форма // отредактирована //
<%= nested_form_for(@product) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="inline-form">
<%= f.fields_for :variations %>
<p><%= f.link_to_add "Add a variation", :variations %></p>
</div>
<div class="actions">
<%= submit_or_cancel(f) %>
</div>
</div>
<% end %>
И вложенная форма являетсябазовый стол с
<table id="new_item">
<tr>
<th>Name</th>
<th>Color</th>
</tr>
<tr>
<td><%= f.text_field :name, :size => 40 %></td>
<td><% for color in Color.all %>
<%= check_box_tag 'variation[color_ids][]', color.id, variation.color_ids.include?(color.id), :id => dom_id(color) %><%= label_tag dom_id(color), color.name, :class => "check_box_label" %>
<% end %>
</td>
</tr>
</table>