Michael Schuerig
2005-Aug-28 19:20 UTC
Save and delete buttons: POST vs. proximity dilemma
I''m in a dilemma: In order to keep GET requests from deleting objects, I''d like to use the button_to helper to get "something" that generates a POST request. Unfortunately, that something is a form and forms can''t be nested. I''d also like to place buttons related to the same form close to each other. At the top are some navigational buttons (links), then comes the delete button somewhere in the middle, at the bottom is the save button. Achieving this without having all of these buttons in the same form doesn''t appear to be possible. Has anyone managed to solve this? The best idea I have right now is to use submit buttons in the same single form, but differentiate them by name. Then, in a before_filter, I could redirect the delete to the actual delete action. I can''t say that this feels good. Michael -- Michael Schuerig Those people who smile a lot mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org Watch the eyes http://www.schuerig.de/michael/ --Ani DiFranco, Outta Me, Onto You
Jarkko Laine
2005-Aug-29 11:51 UTC
Re: Save and delete buttons: POST vs. proximity dilemma
Michael, On 28.8.2005, at 22.20, Michael Schuerig wrote:> > I''m in a dilemma: In order to keep GET requests from deleting objects, > I''d like to use the button_to helper to get "something" that generates > a POST request. Unfortunately, that something is a form and forms > can''t > be nested. > > I''d also like to place buttons related to the same form close to each > other. At the top are some navigational buttons (links), then comes > the > delete button somewhere in the middle, at the bottom is the save > button. Achieving this without having all of these buttons in the same > form doesn''t appear to be possible. > > Has anyone managed to solve this?I just wrote an article [1] about how you can use the AJAX helpers in Rails to solve the exact problem you''re describing. Cheers, //jarkko [1] http://jlaine.net/blog/73/using-rails-ajax-helpers-to-create-safe- state-changing-links -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Michael Schuerig
2005-Aug-29 13:09 UTC
Re: Save and delete buttons: POST vs. proximity dilemma
On Sunday 28 August 2005 21:20, Michael Schuerig wrote:> I''m in a dilemma: In order to keep GET requests from deleting > objects, I''d like to use the button_to helper to get "something" that > generates a POST request. Unfortunately, that something is a form and > forms can''t be nested. > > I''d also like to place buttons related to the same form close to each > other. At the top are some navigational buttons (links), then comes > the delete button somewhere in the middle, at the bottom is the save > button. Achieving this without having all of these buttons in the > same form doesn''t appear to be possible. > > Has anyone managed to solve this?A third option that requires the use of JavaScript prompt = ''Really delete?'' delete_url = url_for(:action => ''destroy'', :id => object) link_to_function(''Delete'', "if (confirm(''#{prompt}'')) { location.replace(''#{delete_url}''); }") This is what I currently use for lack of a better idea. Michael -- Michael Schuerig Not only does lightning not strike mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org twice, it usually doesn''t strike once. http://www.schuerig.de/michael/ --Salman Rushdie, Fury
Steve Downey
2005-Aug-29 14:28 UTC
Re: Save and delete buttons: POST vs. proximity dilemma
Michael Schuerig wrote:>I''m in a dilemma: In order to keep GET requests from deleting objects, >I''d like to use the button_to helper to get "something" that generates >a POST request. Unfortunately, that something is a form and forms can''t >be nested. > >I''d also like to place buttons related to the same form close to each >other. At the top are some navigational buttons (links), then comes the >delete button somewhere in the middle, at the bottom is the save >button. Achieving this without having all of these buttons in the same >form doesn''t appear to be possible. > >Has anyone managed to solve this? > >The best idea I have right now is to use submit buttons in the same >single form, but differentiate them by name. Then, in a before_filter, >I could redirect the delete to the actual delete action. I can''t say >that this feels good. > >Michael > > >this link shows using AJAX to turn the link into a POST: http://weblog.rubyonrails.com/archives/2005/08/26/using-ajax-to-route-dangerous-methods-through-post
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
2005-Aug-29 17:48 UTC
Re: Save and delete buttons: POST vs. proximity dilemma
Hello Michael, Michael Schuerig said the following on 2005-08-28 15:20:> Has anyone managed to solve this? > > The best idea I have right now is to use submit buttons in the same > single form, but differentiate them by name. Then, in a before_filter, > I could redirect the delete to the actual delete action. I can''t say > that this feels good.I use this exact technique, except all my actions are aware of the navigational issues. In fact, my different buttons are next, previous, jump to step X, etc. in a wizard-like flow. I made myself a helper method in my controller which knows about all buttons and redirects to the appropriate spot. Hope that helps, François
Have you considered using CSS (or even AJAX) to put them where you want them? On Sun, 2005-08-28 at 13:20, Michael Schuerig wrote:> I''m in a dilemma: In order to keep GET requests from deleting objects, > I''d like to use the button_to helper to get "something" that generates > a POST request. Unfortunately, that something is a form and forms can''t > be nested. > > I''d also like to place buttons related to the same form close to each > other. At the top are some navigational buttons (links), then comes the > delete button somewhere in the middle, at the bottom is the save > button. Achieving this without having all of these buttons in the same > form doesn''t appear to be possible. > > Has anyone managed to solve this? > > The best idea I have right now is to use submit buttons in the same > single form, but differentiate them by name. Then, in a before_filter, > I could redirect the delete to the actual delete action. I can''t say > that this feels good. > > Michael
Tom Reinhart
2005-Aug-30 03:07 UTC
Re: Save and delete buttons: POST vs. proximity dilemma
On 8/28/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> The best idea I have right now is to use submit buttons in the same > single form, but differentiate them by name. Then, in a before_filter, > I could redirect the delete to the actual delete action. I can''t say > that this feels good.This is how I''ve always done it, and even after having the code there for the longest time, I haven''t found any reason to change it.> MichaelSincerely, Tom Reinhart tom-V0YqjHVuocLQT0dZR+AlfA@public.gmane.org http://AllTom.com/
Justin Forder
2005-Aug-30 07:40 UTC
Re: Save and delete buttons: POST vs. proximity dilemma
Michael Schuerig wrote:> I''m in a dilemma: In order to keep GET requests from deleting objects, > I''d like to use the button_to helper to get "something" that generates > a POST request. Unfortunately, that something is a form and forms can''t > be nested.button_to was a strange addition to Rails - it goes against the grain of HTML. A form defines the scope of content being submitted, and a submit control (button) represents a way of submitting it. Unless you use client-side script you are stuck with the single action URL associated with the form. http://ppewww.ph.gla.ac.uk/~flavell/www/trysub.html discusses the use of multiple submit buttons, with working examples.> I''d also like to place buttons related to the same form close to each > other. At the top are some navigational buttons (links), then comes the > delete button somewhere in the middle, at the bottom is the save > button. Achieving this without having all of these buttons in the same > form doesn''t appear to be possible. > > Has anyone managed to solve this? > > The best idea I have right now is to use submit buttons in the same > single form, but differentiate them by name. Then, in a before_filter, > I could redirect the delete to the actual delete action. I can''t say > that this feels good.Why redirect? In Struts, you would use a DispatchAction or a LookupDispatch action to route to a particular method of the action class based on the value of a parameter in the HTTP request. LookupDispatchAction does this indirectly, doing a reverse lookup on the message resources used to define the names for the submit controls - so it it will work properly with a multilingual application. Could Rails'' routing handle this? regards Justin
Michael Schuerig
2005-Aug-31 08:04 UTC
Re: Save and delete buttons: POST vs. proximity dilemma
On Tuesday 30 August 2005 00:32, Markus wrote:> Have you considered using CSS (or even AJAX) to put them where you > want them?Using CSS for this would require some considerable magic to calculate the exactly where the delete button should go between the other, automatically positioned ones. But as I wrote, some plain client-side JavaScript does the trick. No AJAX required: prompt = ''Really delete?'' delete_url = url_for(:action => ''destroy'', :id => object) link_to_function(''Delete'', "if (confirm(''#{prompt}'')) { location.replace(''#{delete_url}''); }") Michael -- Michael Schuerig Thinking is trying to make up mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org for a gap in one''s education. http://www.schuerig.de/michael/ --Gilbert Ryle