Good day, need help. Help create a view. There is a document form, it has 3 parameters: Product Type, Product , Product Brand . The form should allow you to add different brands of the same product at the same time.
That is, there must be something like this:
- Field: Product Type
- Field: Product
- Field: Product Brand
- Link to add a new Brand, that is, link_to_add_association: brand of the same Product, paragraph 2
New to Rails, so do not judge strictly, thanks in advance for your help.
Below is the application logic:
class Document < ActiveRecord::Base (id, name) has_many :product_documents end class BrandOfProductDocument < ActiveRecord::Base (id, product_id, document_id) belongs_to :document belongs_to :brand_of_product end class BrandOfProduct < ActiveRecord::Base (id, brand_id, product_id) belongs_to :brand belongs_to :product end class Product < ActiveRecord::Base (id, name, product_type_id) belongs_to :product_type end class ProductType < ActiveRecord::Base (id, name) end class Brand < ActiveRecord::Base (id, name) end Document_form.rb:
class DocumentForm < ActiveForm::Base self.main_model = :document association brand_of_product_document do attribute :brand_of_product_id association :brand_of_product do association :product do attribute :name association :product_type do attribute :name end end association :brand do attribute :name end end end end ActiveForm :: Base is from the actionform form
But the form interface itself:
To be more specific, problems with the associations in the view, how to build correctly, tried to follow this example https://github.com/m-Peter/nested-form-examples/tree/master/full-example/after/app/ views / projects .
In the file _form.html.erb I write:
<div id="tags"> <%= f.fields_for :brand_of_product_document do |bpd| %> <%= render 'brand_of_product_document_fields', :f => bpd%> <% end %> <%= link_to_add_association 'add brand_of_product_doc', f, :brand_of_product_document %> </div> In the _brand_of_product_document_fields.html.erb file , what to write is not clear, since my case is not quite similar to the above example.


ActiveForm::Baseis from which gem? 2.Π€ΠΎΡΠΌΠ° Π΄ΠΎΠ»ΠΆΠ½Π° ΠΏΠΎΠ·Π²ΠΎΠ»ΡΡΡ Π΄ΠΎΠ±Π°Π²Π»ΡΡΡ ΡΠ°Π·Π½ΡΠ΅ ΠΌΠ°ΡΠΊΠΈ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈ ΡΠΎΠ³ΠΎ ΠΆΠ΅ ΠΏΡΠΎΠ΄ΡΠΊΡΠ° ΠΎΠ΄Π½ΠΎΠ²ΡΠ΅ΠΌΠ΅Π½Π½ΠΎ.Can you tell more about this? At least you can sketch a shape. 3. The eternal question. What exactly does not work? - anoam