R
R
Robert2016-04-15 22:28:52
JavaScript
Robert, 2016-04-15 22:28:52

Ruby on Rails. Form within form?

So. I have a big (really big) Form Object . Of course , with the help of it I create various associated records (so as not to bother with accept_nested_attributes ...), everything would be fine, but.
The following task arose:
In my form - let it be the form of the Car - there are checkboxes for selecting supported Wheels . And these same supported wheels are added using a separate mold, but as if in the same main one, i.e. the wheel has its own parameters. (picture, dimensions, etc.)
The process is as follows: you entered information about the wheel, clicked on "Add", a Checkbox appeared. Well, accordingly, we can now add this wheel to our Car.

But how do I implement such a form inside my main one? How about independent?
I heard about the cocoon gem and so on and so forth. But this is not quite what you need, because. it essentially works with nested attributes, and that's it.

What I have come to is: add fields to my Form Object describing the wheel, but process them with jquery and send a request to store the wheel in the database, and then render the checkbox if the request was successful.

Is this the right way?

e1476930a39c42cc917ac937025acd1a.JPG

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Filatov, 2016-04-16
@Jowan

Try React for these forms. There you can just track events and show the necessary form depending on this. Here is a good guide that shows an example of working with React.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question