I have a form with a list of things and an action that already exists to update elements.
I want to have another button that, when clicked, triggers triggers to delete selected items.
= form_for @new_item,:url => {:controller => "item_lists",:action => "update_list" } do |f| - @items.each do |it| %input{:type=>"hidden",:name=>"item_list[#{it.id}]position",:value=>it.position, :class=>'position'} %textarea{:name=>"item_list[#{it.id}]field1"} =it.field1 %textarea{:name=>"item_list[#{it.id}]field2"} =it.field2 %input{:type=>'checkbox', :name=>'selected_items[]', :value=>it.id} =(it.valid?) ? "" : it.errors.full_messages %input{:type=>"submit", :value=>"Save changes", :name=>'save'} %input{:type=>"submit", :value=>"Remove selected", :name=>'delete'}
This question seems to indicate that I should check the parameters in my action to find out what was clicked. But it seems messy, my controller can quickly degenerate into a bunch of ifs when I add more actions.
Is there a more elegant way to do this, i.e. make it just go to the correct method?
Thanks for any help ...
Chris source share