hello all, I am working on a simple project on ruby on rails. I need to add a data to the database. I would like to add multiple records of a model using single form and single submit button so that all the records I entered in the form are inserted into database table. I need to design a form with multiple duplicate fields, each set of fields represent a database record. Thanks in Advance -- ---------------------------------------------------------------------------------------------------- Thank You. Best Wishes, BalaRaju Vankala, -- 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 https://groups.google.com/groups/opt_out.
something like that: *<% 1.upto(2) do |i| %> <%= text_field_tag "fields[#{i}][user_name]",'''', :class => "user_name" %> <%= radio_button_tag "fields[#{i}][is_checked]", ''1'', false %><br> <% end %> params[:fields].each do |i, values| u = User.create(values) end* Am Donnerstag, 24. Januar 2013 14:33:45 UTC+1 schrieb BalaRaju Vankala:> > > > hello all, > > I am working on a simple project on ruby on rails. I need to add a data to > the database. I would like to add multiple records of a model using single > form and single submit button so that all the records I entered in the form > are inserted into database table. I need to design a form with multiple > duplicate fields, each set of fields represent a database record. > Thanks in Advance > -- > > ---------------------------------------------------------------------------------------------------- > Thank You. > > Best Wishes, > > BalaRaju Vankala, > >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/O-UeEUuWFGoJ. For more options, visit https://groups.google.com/groups/opt_out.
BalaRaju Vankala
2013-Jan-24 14:49 UTC
Re: Re: Add Multiple Records of a model using single form
Thank you @Werner its Working. On Thu, Jan 24, 2013 at 7:59 PM, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>wrote:> something like that: > > *<% 1.upto(2) do |i| %> > <%= text_field_tag "fields[#{i}][user_name]",'''', :class => "user_name" %> > <%= radio_button_tag "fields[#{i}][is_checked]", ''1'', false %><br> > <% end %> > > params[:fields].each do |i, values| > u = User.create(values) > end* > > > > Am Donnerstag, 24. Januar 2013 14:33:45 UTC+1 schrieb BalaRaju Vankala: > >> >> >> hello all, >> >> I am working on a simple project on ruby on rails. I need to add a data >> to the database. I would like to add multiple records of a model using >> single form and single submit button so that all the records I entered in >> the form are inserted into database table. I need to design a form with >> multiple duplicate fields, each set of fields represent a database record. >> Thanks in Advance >> -- >> ------------------------------**------------------------------** >> ------------------------------**---------- >> Thank You. >> >> Best Wishes, >> >> BalaRaju Vankala, >> >> -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/O-UeEUuWFGoJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ---------------------------------------------------------------------------------------------------- Thank You. Best Wishes, BalaRaju Vankala, 8886565300. -- 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 https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2013-Jan-24 15:04 UTC
Re: Re: Add Multiple Records of a model using single form
On Thu, Jan 24, 2013 at 10:49 PM, BalaRaju Vankala <foreverbala4u-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Thank you @Werner its Working. > > > On Thu, Jan 24, 2013 at 7:59 PM, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>wrote: > >> something like that: >> >> *<% 1.upto(2) do |i| %> >> <%= text_field_tag "fields[#{i}][user_name]",'''', :class => "user_name" %> >> <%= radio_button_tag "fields[#{i}][is_checked]", ''1'', false %><br> >> <% end %> >> >> params[:fields].each do |i, values| >> u = User.create(values) >> end* > >Just for clarification, you don''t need to supply an index <% 2.times do %> <%= text_field_tag "fields[][user_name]",'''', :class => "user_name" %> <%= radio_button_tag "fields[][is_checked]", ''1'', false %><br> <% end %> should be enough :) params[:fields] will be an array of attributes instead of a hash so you can do User.create params[:fields] (I think :D)> >> >> >> >> Am Donnerstag, 24. Januar 2013 14:33:45 UTC+1 schrieb BalaRaju Vankala: >> >>> >>> >>> hello all, >>> >>> I am working on a simple project on ruby on rails. I need to add a data >>> to the database. I would like to add multiple records of a model using >>> single form and single submit button so that all the records I entered in >>> the form are inserted into database table. I need to design a form with >>> multiple duplicate fields, each set of fields represent a database record. >>> Thanks in Advance >>> -- >>> ------------------------------**------------------------------** >>> ------------------------------**---------- >>> Thank You. >>> >>> Best Wishes, >>> >>> BalaRaju Vankala, >>> >>> -- >> 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 >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/O-UeEUuWFGoJ. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > > ---------------------------------------------------------------------------------------------------- > Thank You. > > Best Wishes, > > BalaRaju Vankala, > 8886565300. > > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- 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 https://groups.google.com/groups/opt_out.