# Editing multiple records at once

**URL:** <https://www.ruby-forum.com/t/editing-multiple-records-at-once/160642>\
**Category:** Rails\
**Created:** [February 18, 2009, 1:18pm UTC](https://www.ruby-forum.com/t/editing-multiple-records-at-once/160642 "2009-02-18T13:18:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sa125](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sa125](https://www.ruby-forum.com/u/sa125)\
**Post date:** [February 18, 2009, 1:18pm UTC](https://www.ruby-forum.com/t/editing-multiple-records-at-once/160642/1 "2009-02-18T13:18:52Z")

</div>

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  
partial:

# \_product.html.erb

\<%= check\_box\_tag ‘modify’ %\>  
\<%=h product.name %\>  
\<%=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.

---

<div class="post-metadata">

**Author:** ![sa125](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sa125](https://www.ruby-forum.com/u/sa125)\
**Post date:** [February 18, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/editing-multiple-records-at-once/160642/2 "2009-02-18T16:34:56Z")

</div>

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 🙂
