I have a few actions which, after completing, i want to return to the action that called them. Currently the way i''m doing this is passsing through a parameter with the name of the calling method, eg <%= link_to ''Delete this picture'', :action => ''delete_picture'', :id => picture, :came_from => "edit_story" %> Then in the callee method i refer to this in the redirect_to part: redirect_to :action => params[:came_from], :id => @story if params[:came_from] flash[:warning] = "Couldn''t find a story to return to, returning to list" redirect_to :action => "list" Is there a nicer way to get the calling method, without having to remember to explicitly pass it through? Or a nicer alternative to what i''m doing, generally? thanks max -- 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 -~----------~----~----~----~------~----~------~--~---
Mikkel Bruun
2007-Aug-08 12:11 UTC
Re: Q about returning to the action that called the method
Max Williams wrote:> Is there a nicer way to get the calling method, without having to > remember to explicitly pass it through? Or a nicer alternative to what > i''m doing, generally? > > thanks > maxtry to mess around with redirect_to :back and see if it helps you... M^ -- 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 -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld
2007-Aug-08 12:34 UTC
Re: Q about returning to the action that called the method
(continuing Mikkel''s post) redirect_to :back ================(taken from api) back: Back to the page that issued the request. Useful for forms that are triggered from multiple places. Short-hand for redirect_to(request.env["HTTP_REFERER"]) The redirection happens as a "302 Moved" header. When using redirect_to :back, if there is no referrer, RedirectBackError will be raised. You may specify some fallback behavior for this case by rescueing RedirectBackError. ( http://api.rubyonrails.com/classes/ActionController/Base.html#M000271 ) -- 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 -~----------~----~----~----~------~----~------~--~---
Max Williams
2007-Aug-08 13:31 UTC
Re: Q about returning to the action that called the method
Mikkel Bruun wrote:> > try to mess around with redirect_to :back and see if it helps you... >Trying this made me realise that when i delete a picture, i actually need to go back TWO steps, not just one. So i think i''m better off sticking with my explicit parameter passing method to avoid confusion. "redirect_to :back" is good to know though, might be useful in future. Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---