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 !!
on 2005-12-01 08:37
on 2005-12-01 10:22
On 1.12.2005, at 8.37, KiteSurfer KiteSurfer wrote: > But.... this redirects me back to where I currently am ie (B). > 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
on 2005-12-01 10:38
here is what we did - i think you can easily adapt it to fort your particular issue http://albert.bagasie.com/RailsTips/JumpBack
on 2005-12-01 16:29
Good stuff. Thank you both !!
on 2005-12-02 03:38
On Dec 1, 2005, at 12:18 AM, Jarkko L. wrote: >> either >> 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 Z. WebMaster Yakima Herald-Republic Newspaper firstname.lastname@example.org 509-577-7732