# Issue updating multiple database rows from single form submi

**URL:** <https://www.ruby-forum.com/t/issue-updating-multiple-database-rows-from-single-form-submi/131758>\
**Category:** Rails\
**Created:** [March 13, 2008, 2:04am UTC](https://www.ruby-forum.com/t/issue-updating-multiple-database-rows-from-single-form-submi/131758 "2008-03-13T02:04:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpigford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5a626/32.png) [@jpigford](https://www.ruby-forum.com/u/jpigford)\
**Post date:** [March 13, 2008, 2:04am UTC](https://www.ruby-forum.com/t/issue-updating-multiple-database-rows-from-single-form-submi/131758/1 "2008-03-13T02:04:01Z")

</div>

So I’ve got a form that loops through items with a text\_field\_tag and  
text\_area\_tag that lists items in the database to be edited.

I want to submit this form and have it loop through the items and update  
the rows based on the ids in the name attribute of the input tag.

The names are formatted like photos[1234][description].

Here’s what I’ve got so far but i’m not sure really how to get it  
functioning correctly in the controller: (and note, I’m not sold on  
going about this the following way…it’s just what I’ve got thus far.

## View

\<% form\_for :photo, :url =\> { :action =\> “update\_complete” } do |form|  
%\>  
\<% for photo in @photos %\>  
\<%= text\_field\_tag “photos[#{photo.id}][filename]”, photo.filename  
%\>  
\<%= text\_area\_tag “photos[#{photo.id}][description]”,  
photo.description %\>  
\<% end %\>  
\<% end %\>

## Controller

def update\_complete  
params[:photos].each do |id|  
@photo = Photo.find(id)  
@photo.update\_attributes(params[:photos])  
end  
end
