Josh Pigford
2008-Mar-13 01:04 UTC
Issue updating multiple database rows from single form submi
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---