Hi, I have a page (A) that contains a table with links in one column. When the user hits a link it goes to another page (B) which is a read only form page with a done button. This page (B) is being reused in various parts of the app read pages (C) and (D). Thus when the user clicks ''Done'' it needs to return back to where she comes from ie either (A), (C) or (D). I thought with the new Rails 0.14.3 I could just do redirect_to :back and all my ills would be cured. But.... this redirects me back to where I currently am ie (B). I am sure this is a very common problem out there. In my java life I would create something in the session and consume it when this exact situation arises. Is there a magic rails spell that I could use for this situation ? I am not sure how to get the URL of page (A) so I can stach it in the session for later retrieval or somehow push both the controller and action of the page where the request was originated (??) Sample code please... Thank you all !! -- Posted via http://www.ruby-forum.com/.
On 1.12.2005, at 8.37, KiteSurfer KiteSurfer wrote:> Hi, > > I have a page (A) that contains a table with links in one column. > When the user hits a link it goes to another page (B) which is a read > only form page with a done button. This page (B) is being reused in > various parts of the app read pages (C) and (D). Thus when the user > clicks ''Done'' it needs to return back to where she comes from ie > either > (A), (C) or (D). I thought with the new Rails 0.14.3 I could just do > redirect_to :back and all my ills would be cured. > But.... this redirects me back to where I currently am ie (B). > > I am sure this is a very common problem out there. In my java > life I > would create something in the session and consume it when this exact > situation arises. > > Is there a magic rails spell that I could use for this > situation ? I > am not sure how to get the URL of page (A) so I can stach it in the > session for later retrieval or somehow push both the controller and > action of the page where the request was originated (??) > > Sample code please...def authenticate unless session[:user_id] session[:return_to] = @request.request_uri redirect_to :controller => "login" return false end end # login_controller.rb def login if @user = User.authenticate(params[:name], params[:password]) session[:user_id] = @user.id if session[:return_to] redirect_to(session[:return_to]) session[:return_to] = nil end end end (lots of lines omitted warning) //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
here is what we did - i think you can easily adapt it to fort your particular issue http://albert.bagasie.com/RailsTips/JumpBack KiteSurfer KiteSurfer wrote:>Hi, > > I have a page (A) that contains a table with links in one column. >When the user hits a link it goes to another page (B) which is a read >only form page with a done button. This page (B) is being reused in >various parts of the app read pages (C) and (D). Thus when the user >clicks ''Done'' it needs to return back to where she comes from ie either >(A), (C) or (D). I thought with the new Rails 0.14.3 I could just do >redirect_to :back and all my ills would be cured. >But.... this redirects me back to where I currently am ie (B). > > I am sure this is a very common problem out there. In my java life I >would create something in the session and consume it when this exact >situation arises. > > Is there a magic rails spell that I could use for this situation ? I >am not sure how to get the URL of page (A) so I can stach it in the >session for later retrieval or somehow push both the controller and >action of the page where the request was originated (??) > > Sample code please... > >Thank you all !! > > >
Good stuff. Thank you both !! -- Posted via http://www.ruby-forum.com/.
On Dec 1, 2005, at 12:18 AM, Jarkko Laine wrote:> > On 1.12.2005, at 8.37, KiteSurfer KiteSurfer wrote: > >> Hi, >> >> I have a page (A) that contains a table with links in one column. >> When the user hits a link it goes to another page (B) which is a read >> only form page with a done button. This page (B) is being reused in >> various parts of the app read pages (C) and (D). Thus when the user >> clicks ''Done'' it needs to return back to where she comes from ie >> either >> (A), (C) or (D). I thought with the new Rails 0.14.3 I could just do >> redirect_to :back and all my ills would be cured. >> But.... this redirects me back to where I currently am ie (B). >> >> I am sure this is a very common problem out there. In my java >> life I >> would create something in the session and consume it when this exact >> situation arises. >> >> Is there a magic rails spell that I could use for this >> situation ? I >> am not sure how to get the URL of page (A) so I can stach it in the >> session for later retrieval or somehow push both the controller and >> action of the page where the request was originated (??) >> >> Sample code please...def store_location @session[''return-to''] = @request.request_uri end # move to the last store_location call or to the passed default one def redirect_back_or_default(default) if @session[''return-to''].nil? redirect_to default else redirect_to_url @session[''return-to''] @session[''return-to''] = nil end end Then you can put a call to store location before you redirect to a new page. Then once they finish with that page you call redirect_back_or_default to send them to the location stored in the session. Cheers- -Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org 509-577-7732