I used Railscast episode 198 to create a form that allows me to edit multiple objects individually using checkboxes. I'd like to be able to select "Edit" or "Delete" actions after checking off the boxes of the items I would like to change. I've added this to my photos_controller.rb for the edit action:
def edit_individual
@photos = Photo.find(params[:photo_ids])
end
def update_individual
@user = current_user
@photos = Photo.update(params[:photos].keys, params[:photos].values).reject { |p| p.errors.empty? }
if @photos.empty?
flash[:notice] = "Products updated"
redirect_to photos_url
else
render :action => "edit_individual"
end
end
And in my view, I am adding this line of code when I loop through each photo to display it:
<%= form_tag edit_individual_photos_path, :method => "get" do %>
... #loop through all photos and add a checkbox
<%= check_box_tag "photo_ids[]", photo.id %>
<%= submit_tag "Edit", :class => "btn btn-large btn-inverse" %>
This works fine, but I can't figure out how to add another submit tag to the form to delete the selected items instead of just edit them. Does anyone know how I could pass the array of photo_ids as a parameter and destroy them?