Mohamad El-Husseini
2012-Jan-10 00:05 UTC
Newbie question: How to save multiple records in a single form
Started learning Ruby and RoR a couple of days ago and I''m working on a dummy app. I want to allow a user to save 5 records at the same time using a single form. Let''s assume "contact" records, with each one consisting of a single "name" field. It''s a "user has_many contacts" relationship. Anyone aware of tutorials/documentation on how to achieve this? I''m having a hard time modifying the code from a single record into multiple ones. Chiefly... 1- How to display 5 text fields in the form/correct form tag to use. 2- How to pass an array of those 5 objects to the "create" method (if it''s an array that I should pass) 3- How to create the instance variable that has the 5 objects in the "new" method so it''s available to the form -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/fA6MgGFd13QJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ahmy Yulrizka
2012-Jan-11 10:39 UTC
Re: Newbie question: How to save multiple records in a single form
Here are good example http://railscasts.com/episodes/73-complex-forms-part-1 Ahmy Yulrizka On Tue, Jan 10, 2012 at 7:05 AM, Mohamad El-Husseini <husseini.mel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Started learning Ruby and RoR a couple of days ago and I''m working on a > dummy app. > > I want to allow a user to save 5 records at the same time using a single > form. Let''s assume "contact" records, with each one consisting of a single > "name" field. It''s a "user has_many contacts" relationship. > > Anyone aware of tutorials/documentation on how to achieve this? I''m having > a hard time modifying the code from a single record into multiple ones. > Chiefly... > > 1- How to display 5 text fields in the form/correct form tag to use. > 2- How to pass an array of those 5 objects to the "create" method (if it''s > an array that I should pass) > 3- How to create the instance variable that has the 5 objects in the "new" > method so it''s available to the form > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/fA6MgGFd13QJ. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Angelo Cordova
2012-Jan-11 17:05 UTC
Re: Newbie question: How to save multiple records in a single form
On 9 ene, 21:05, Mohamad El-Husseini <husseini....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Started learning Ruby and RoR a couple of days ago and I''m working on a > dummy app. > > I want to allow a user to save 5 records at the same time using a single > form. Let''s assume "contact" records, with each one consisting of a single > "name" field. It''s a "user has_many contacts" relationship. > > Anyone aware of tutorials/documentation on how to achieve this? I''m having > a hard time modifying the code from a single record into multiple ones. > Chiefly... > > 1- How to display 5 text fields in the form/correct form tag to use. > 2- How to pass an array of those 5 objects to the "create" method (if it''s > an array that I should pass) > 3- How to create the instance variable that has the 5 objects in the "new" > method so it''s available to the formLook at these examples http://railscasts.com/episodes/196-nested-model-form-part-1 http://railscasts.com/episodes/197-nested-model-form-part-2 or even you could try nested form gem https://github.com/ryanb/nested_form -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.