Forum: Ruby on Rails editing multiple records at once

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
sa 1. (Guest)
on 2009-02-18 14:18
I want to be able to change a property on multiple records in my app. I
thought about adding a checkbox so that one can pick which records to
update. The question is how to implement the actual update - if the
checkbox isn't part of the model, how can I iterate the records in the
view and see which are selected? My records are displayed using a

# _product.html.erb

<%= check_box_tag 'modify' %>
<%=h %>
<%=h product.price %>

# index.html.erb

<% form_tag %>

<%= text_field_tag 'price' %>
<%= render :partial => 'product', @collection => @products %>
<%= submit_tag 'save' %>

<% end %>

Also, what kind of form should I put this in, and how to catch which
boxes are selected... I'm pretty clueless about this - thanks.
sa 1. (Guest)
on 2009-02-18 17:34
I've decided on a different approach and I could use some help:

The page containing the records to modify also contains a small form to
filter the displayed records. It uses observe_form to periodically call
a function to filter the view.

I want to use this form filter as a selector on which records to update
- it will be a two step process:

1. the user picks which records to update by applying the filter.
2. the user will update attributes using a different form.

The filter works by taking the selected attributes in it's form and
calling a helper function that returns a :conditions array "cond" to use
with activerecord's find function - @products = Product.find(:all,
:conditions => cond).

This is all fine, but I have one problem - how can get have the filter's
conditions available to the updating function (which isn't called from
the observe_form helper)?

If I could have the :conditions available when I search which records to
update, then everything will be simpler. Any advice will be more than
welcomed :)
This topic is locked and can not be replied to.