I''d like my create and edit forms to both have a Cancel button that redirects back to the referring page. To date, the best approach I''ve found is to include an additional submit_tag with a :name parameter of cancel. Then inside the controller I have in if/else statement that checks for the existence of params[:cancel]. If it exists, I issue a redirect to the referring page. Otherwise, I proceed with the create/ update. Is there a better way? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Why not just do javascript:history.back()? - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Sat, Feb 21, 2009 at 5:42 PM, ericindc <ericmilford-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''d like my create and edit forms to both have a Cancel button that > redirects back to the referring page. To date, the best approach I''ve > found is to include an additional submit_tag with a :name parameter of > cancel. Then inside the controller I have in if/else statement that > checks for the existence of params[:cancel]. If it exists, I issue a > redirect to the referring page. Otherwise, I proceed with the create/ > update. > > Is there a better way? > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
eric, i didn''t find a better solution either. i''d not choose the javascript solution for two reasons. because it depends on the client''s configuration/behavior and, most importantly, because sometimes the user wants to see an explicit message from the server that the action was indeed canceled (if her credit card number was in the page, for example). -- 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 -~----------~----~----~----~------~----~------~--~---
PP Junty wrote:> eric, i didn''t find a better solution either. i''d not choose the > javascript solution for two reasons. because it depends on the client''s > configuration/behavior and, most importantly, because sometimes the user > wants to see an explicit message from the server that the action was > indeed canceled (if her credit card number was in the page, for > example).I use a filter - before_filter :check_for_cancel, :only => [:create, :update] and a method def check_for_cancel if params[:commit] == ''Cancel'' redirect_back_or_default....... end end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
andrew, the problem i see is that you depend on the label of the button. if a user wants to change the label of one button, let''s say to "Abort", then it requires another method for this particular button. using <%= submit_tag ''Any Label'', :name => ''cancel'' %> and def check_for_cancel unless params[:cancel].blank? redirect_back_or_default....... end end you can avoid that. Andrew Porter wrote:> > I use a filter - > before_filter :check_for_cancel, :only => [:create, :update] > > and a method > > def check_for_cancel > if params[:commit] == ''Cancel'' > redirect_back_or_default....... > 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 -~----------~----~----~----~------~----~------~--~---
On Mon, Mar 16, 2009 at 6:58 PM, PP Junty <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > andrew, the problem i see is that you depend on the label of the button. > if a user wants to change the label of one button, let''s say to "Abort", > then it requires another method for this particular button. > using > > <%= submit_tag ''Any Label'', :name => ''cancel'' %> > > and > > def check_for_cancel > unless params[:cancel].blank? > redirect_back_or_default....... > end > end > > you can avoid that. > > > Andrew Porter wrote: >> >> I use a filter - >> before_filter :check_for_cancel, :only => [:create, :update] >> >> and a method >> >> def check_for_cancel >> if params[:commit] == ''Cancel'' >> redirect_back_or_default....... >> end >> end > > -- > Posted via http://www.ruby-forum.com/. > > > >I just add a link next to the submit tag labelled ''cancel'' with a link to an appropriate page. Technically a button should be used for an action while cancelling is technically the absence of an action. Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-17 07:13 UTC
Re: Adding a Form Cancel Button
On 17 Mar., 07:31, Andrew Timberlake <and...-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> wrote:> I just add a link next to the submit tag labelled ''cancel'' with a link > to an appropriate page. > Technically a button should be used for an action while cancelling is > technically the absence of an action.I totally agree. Using a link instead of a button has several advantages. That the user does not expect anything destructive to happen when clicking a link, is one. And you don''t need to clutter your controller with logic for the cancel button. The only thing you need is a simple #link_to refering to an appropriate page. -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2009/3/17 rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org <rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org>> > > > On 17 Mar., 07:31, Andrew Timberlake <and...-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> > wrote: > > I just add a link next to the submit tag labelled ''cancel'' with a link > > to an appropriate page. > > Technically a button should be used for an action while cancelling is > > technically the absence of an action. > > I totally agree. Using a link instead of a button has several > advantages. That the user does not expect anything destructive to > happen when clicking a link, is one. And you don''t need to clutter > your controller with logic for the cancel button. The only thing you > need is a simple #link_to refering to an appropriate page. >At the risk of being contentious, I suggest that the above are non-Railsy answers. It may be strictly correct to say that Cancel is an instruction to do nothing and should not therefore be a button. Millions of people, however, are used to seeing cancel buttons all over the place and expect it to throw away any data they have entered on a form and ensure that they have done no harm. Rails stresses the importance of following conventions and should therefore follow this convention and not try to enforce unconventional ideas on the user. In fact as I think about it, a Cancel button does take some action (at least from the users perspective, which is what matters), it discards any data he has entered into the form. The fact that this is a do-nothing action in the Rails code is irrelevant to what the user interface should be. Colin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-17 14:52 UTC
Re: Adding a Form Cancel Button
On 17 Mar., 10:18, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/3/17 ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org <ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org> > > > > > > > > > On 17 Mar., 07:31, Andrew Timberlake <and...-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> > > wrote: > > > I just add a link next to the submit tag labelled ''cancel'' with a link > > > to an appropriate page. > > > Technically a button should be used for an action while cancelling is > > > technically the absence of an action. > > > I totally agree. Using a link instead of a button has several > > advantages. That the user does not expect anything destructive to > > happen when clicking a link, is one. And you don''t need to clutter > > your controller with logic for the cancel button. The only thing you > > need is a simple #link_to refering to an appropriate page. > > At the risk of being contentious, I suggest that the above are non-Railsy > answers. It may be strictly correct to say that Cancel is an instruction to > do nothing and should not therefore be a button. Millions of people, > however, are used to seeing cancel buttons all over the place and expect it > to throw away any data they have entered on a form and ensure that they have > done no harm. Rails stresses the importance of following conventions and > should therefore follow this convention and not try to enforce > unconventional ideas on the user. > > In fact as I think about it, a Cancel button does take some action (at least > from the users perspective, which is what matters), it discards any data he > has entered into the form. The fact that this is a do-nothing action in the > Rails code is irrelevant to what the user interface should be.Well, I can see what you mean. I do not want to discuss it further, just wanted to mention that you could use the #button_to method to avoid cluttering your controller. Problem is, you need to put it outside the form since the method outputs a <form> itself. -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---