Есть 3 модели: Товары, Заказы, Связывающая модель
Product:
has_many :purchaseds, :dependent => :destroy
has_many :orders, :through => :purchaseds
Order
has_many :purchaseds, :dependent => :destroy
has_many :products, through: :purchaseds
accepts_nested_attributes_for :purchaseds
Purchased
belongs_to :product
belongs_to :order
В контролере пишу:
@order = Order.new()
@products.each do |p|
@order.purchaseds.build({
:product_id => p.id
})
end
В итоге в форме у меня пусто!= form_for(@order) do |f|
- f.fields_for :purchaseds do |p|
= debug p
= debug @order.purchaseds выводит массив объектов как положено.