Answer the question
In order to leave comments, you need to log in
Why doesn't Ruby on Rails fields_for work?
There are 3 models: Products, Orders, Linking model
Product:
has_many :purchaseds, :dependent => :destroy
has_many :orders, :through => :purchaseds
has_many :purchaseds, :dependent => :destroy
has_many :products, through: :purchaseds
accepts_nested_attributes_for :purchaseds
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
Answer the question
In order to leave comments, you need to log in
Found an error
= form_for(@order) do |f|
= f.fields_for :purchaseds do |p|
= debug p
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question