So far, I haven''t had the need for a page which displays blank fields to create multiple new records in one shot . In other words, on one page have multiple rows of input fields with each row corresponding to a record in a table. Using ''file_column'' (thanks Sebastian!), I''d like to be able to upload multiple files at once. When UPDATING records, the ''object[]'' syntax can be used within a block but obviously this doesn''t work with new records because there aren''t any existing records to iterate. Without replacing the control helpers with manual html, is there a way to do the same for NEW records? -- Hammed Malik _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hammed Malik <hammed-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:> So far, I haven''t had the need for a page which displays blank fields to > create multiple new records in one shot . In other words, on one page have > multiple rows of input fields with each row corresponding to a record in a > table.My first attempt would be something like this: <% for i in 1..10 -%> <%= text_field_tag "foo[#{i}][attribute]" %> <% end %> Then in the controller params[:foo].each do |array_item| new_obj = Foo.new if ! new_obj.update_attributes(array_item) flash[:error] = "Error creating this item" end end In the controller params[:foo] should be an array of hashes where each key is one of the inputs from your form. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
Thanks Doug! I''ve built name attributes for tags similarly in the past but it never occured to me to use the *_tag methods. On 9/6/05, Doug Alcorn <doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org> wrote:> > Hammed Malik <hammed-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > So far, I haven''t had the need for a page which displays blank fields to > > create multiple new records in one shot . In other words, on one page > have > > multiple rows of input fields with each row corresponding to a record in > a > > table. > > My first attempt would be something like this: > > <% for i in 1..10 -%> > <%= text_field_tag "foo[#{i}][attribute]" %> > <% end %> > > Then in the controller > > params[:foo].each do |array_item| > new_obj = Foo.new > if ! new_obj.update_attributes(array_item) > flash[:error] = "Error creating this item" > end > end > > In the controller params[:foo] should be an array of hashes where each > key is one of the inputs from your form. > -- > doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Hammed Malik _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails