Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple records of model in a single form

I would like to create a form which works in the connection table between a "M:N" relation. So the user is able to add multiple rows of a parent model in one form.

Can some help me to bring this working? What should be the associations? My problem is the same like here.

Thank you very much for your help!

like image 380
shub Avatar asked Jan 23 '26 23:01

shub


2 Answers

Looks like you are trying to do some nesting have you tried these tuts from railscasts

http://railscasts.com/episodes/196-nested-model-form-part-1

http://railscasts.com/episodes/197-nested-model-form-part-2

Also checkout this for some guidance on the types of relations you want

http://railscasts.com/episodes/47-two-many-to-many

like image 107
Hishalv Avatar answered Jan 26 '26 13:01

Hishalv


You could always do that manually inside the controller without rails' form_for helper.

Thats actually what the second part of the answer to the question you linked to suggests.

Just like the answer mentions, giving <input> fields names ending with [] (e.g. <input type="text" name="field[]">) results in that field being an array in the params hash inside the controller.

like image 30
maiwald Avatar answered Jan 26 '26 12:01

maiwald