In transitioning a WebObjects app to Rails, I''ve run into this question: How do I use multiple submit buttons in a single form? I have a list of items that are in the database. Each list item has a ''Delete'' button that looks like this:
** Sorry, I let the last one go early! ** In transitioning a WebObjects app to Rails, I''ve run into this question: How do I use multiple submit buttons in a single form? I have a list of items that are in the database. Each list item has a ''Delete'' button that looks like this: <li><a class="rec" href="/admin/user_admin/edit/4"></a> <input class="del" name="4" type="submit" value="Delete" /></li> How can I have my destroy method pick up the right item? Anyone done this? Cheers, Hunter
On Saturday 16 July 2005 23:53, Hunter Hillegas wrote:> ** Sorry, I let the last one go early! ** > > In transitioning a WebObjects app to Rails, I''ve run into this > question: > > How do I use multiple submit buttons in a single form? > > I have a list of items that are in the database. Each list item has a > ''Delete'' button that looks like this: > > <li><a class="rec" href="/admin/user_admin/edit/4"></a> <input > class="del" name="4" type="submit" value="Delete" /></li> > > How can I have my destroy method pick up the right item?Give all the buttons the same name, then check its value in your action. <%= submit_tag ''One'', :name => ''mybutton'' %> <%= submit_tag ''Two'', :name => ''mybutton'' %> In your action @params[''mybutton''] will equal One or Two.> Anyone done this? > > Cheers, > Hunter > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- Dominic Marks
Thanks. The problem is that all the buttons need to show the word ''Delete'' when rendered in the browser. They cannot be unique. Any other suggestions?> From: Dominic Marks <dom-oCiW/wK895g3fM+T6T0RSip2UmYkHbXO@public.gmane.org> > Date: Sun, 17 Jul 2005 00:09:44 +0100 > To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Cc: Hunter Hillegas <lists-HAWAbpnI61OZ1JSuHaJ1sQC/G2K4zDHf@public.gmane.org> > Subject: Re: [Rails] Multiple Submit Buttons in One Form > > On Saturday 16 July 2005 23:53, Hunter Hillegas wrote: >> ** Sorry, I let the last one go early! ** >> >> In transitioning a WebObjects app to Rails, I''ve run into this >> question: >> >> How do I use multiple submit buttons in a single form? >> >> I have a list of items that are in the database. Each list item has a >> ''Delete'' button that looks like this: >> >> <li><a class="rec" href="/admin/user_admin/edit/4"></a> <input >> class="del" name="4" type="submit" value="Delete" /></li> >> >> How can I have my destroy method pick up the right item? > > Give all the buttons the same name, then check its value in your > action. > > <%= submit_tag ''One'', :name => ''mybutton'' %> > <%= submit_tag ''Two'', :name => ''mybutton'' %> > > In your action @params[''mybutton''] will equal One or Two. > >> Anyone done this? >> >> Cheers, >> Hunter >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > -- > Dominic Marks
Hunter Hillegas wrote:>Thanks. > >The problem is that all the buttons need to show the word ''Delete'' when >rendered in the browser. > >They cannot be unique. > >Any other suggestions? > >Just an idea, I haven''t tested it at all, but this might just do the trick. You could give the select tags names like "delete[id]" all with the label "Delete", then @params[:delete] would give you an array with id to delete. Something along these line sshould work. hth, -Dane