S
S
Sergey Fuksman2014-10-08 19:44:18
Ruby on Rails
Sergey Fuksman, 2014-10-08 19:44:18

How to create a complex dynamic form in Rails 4?

Hello.
According to the project, it is necessary to solve the following problem:
1. There is a Document model
2. There is a Record model
3. Models are connected to each other through has_and_belongs_to_many
4. On the Document creation form, it is necessary to fill in the fields for records included in this document
5. The number of records for documents is not limited , therefore, by default, fields for only one Record are displayed in the form
6. Fields for additional records must be added by clicking the "Add Record" button/link
7. When saving the form, one document must be created, the declared number of records and links between them
I don't know how to implement points 6 and 7. Could you help me with the code or links to the necessary documentation or projects where this is implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mstfa, 2014-10-09
@fuksman

railscasts.com/episodes/196-nested-model-form-part-1
railscasts.com/episodes/197-nested-model-form-part-2

_
_ _, 2014-10-08
@AMar4enko

6. Using JavaScript
7. apidock.com/rails/ActiveRecord/NestedAttributes/Cl...

V
vsuhachev, 2014-10-09
@vsuhachev

In general, you can do it differently, AJAX has already been advised
. Another option is to separate the creation of a document and the creation of document records into different controllers, but arrange the index page in the Records controller as editing a document.
This can be done using a template (layout) for the Records controller. Again, if you want ajax, then you can screw it later

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question