I am trying to create a form that allows me to submit new entries for an association in which association entries are combined.
class Product < AR::Base
has_many :properties
accepts_nested_attributes_for :properties
end
Please note that a series of properties are built in the controller for the product, therefore @product.properties.empty? # => false.
Below fields_forgives me the correct entries with names such as product[properties_attributes][0][value].
= form.fields_for :properties do |pform|
= pform.input :value
But as soon as I try to group the association, it no longer generates inputs with the correct names:
- @product.properties.group_by(&:group_name).each do |group_name, properties|
%h3= group_name
= form.fields_for properties do |pform|
= pform.input :value
Create inputs for which the attribute name, for example product[product_property][value], when it should be product[property_attributes][0][value]in accordance with the first example.
In the Rails documentation, you can do the following:
= form.fields_for :properties_attributes, properties do |pform|
But this gives the error "undefined method value for the array".
source
share