On Jul 6, 2005, at 8:59 AM, Thomas Parslow wrote:> Hi,
>
> I''m new to Rails (and Ruby in general) so please excuse me if this
is
> an obvious question.
>
> I want to display a form to allow editing of multiple database rows at
> the same time, I want to show a bunch of order_lines and allow the
> user to change fields (such as quantity or notes) on then click the
> submit button to have all their changes written to the database.
>
> Do I have to do this using the text_field_tag style helper functions
> then manually update the database from the controller or is there an
> easier way (maybe using the text_field style helpers)?
>
This isn''t a very well documented feature of Rails, so I''m not
surprised you haven''t found "the rails way" :) If you have
some
time, it would certainly be an asset to the community if you posted
an example of what you get working on the wiki.
In your view, use this "magic" syntax:
<% for @order_line in @order_lines %>
<%= text_field "order_line[]", "quantity" %>
<% end %>
The output will look something like this:
<input type="text" id="order_line_1_quantity"
name="order_line[1]
[quantity]" value="">
Which means that you should be able to scoop up the results in your
controller like this:
def update
OrderLine.update @params[:order_line].keys, @params
[:order_line].values
end
Here''s a previous email where I scraped together all known
documentation up to this point:
http://article.gmane.org/gmane.comp.lang.ruby.rails/12158/match=+ann
+four+days+rails+arrays
Duane Johnson
(canadaduane)
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails