Answer the question
In order to leave comments, you need to log in
Rails: form with the ability to select an existing one or add a new one, what's the best way to do it?
Good afternoon.
There is a need to have a form on which you can either select data from the existing one (now I'm trying to implement auto-completion) or enter new data (in total there are 4 input fields).
I made an auto-completion, the fields will be filled if there is a match, but when saving, an error occurs. the data does not have an id, because a form for a new entry... Yes, I understand that you can add a node with data by id, but somehow it's not rude to write this: agency_order[passengers_attributes][0][client_attributes][id] in the selector. Maybe there is some practice in this regard: make a select, and next to the "add" button (although in this case the addition will be more than the selection from the database).
Thanks for any thoughts.
Answer the question
In order to leave comments, you need to log in
You will have to do everything in javascript. If you need an id, then pass it along with the autocomplete text and then submit the form with the desired id.
Maybe I misunderstood the problem, but why save the attributes for the new entry separately from the entry itself, instead of saving the new entry along with the nested attributes?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question