Note that there are some explanatory texts on larger screens.

plurals
  1. PORailsTutorial.org Chapter9 session.delete issues
    text
    copied!<p>I'm following the tutorial on <a href="http://ruby.railstutorial.org" rel="nofollow">http://ruby.railstutorial.org</a></p> <p>Specifically, chapter 9 (9.2.3) <a href="http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#top" rel="nofollow">http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#top</a></p> <p>I've managed to get the part when a user will get prompted to login when accessing a restricted page then be redirected back to the restricted page after successfully logging in.</p> <p>I'm trying to get it so that after one redirects to the protected page, the next login attempt will direct back to the main user profile page, however, <code>session.delete(:return_to)</code> doesn't appear to be working and the user is repeatedly directed back to the originally saved protected page. Here's my code:</p> <p>My session Controller:</p> <pre><code>class SessionsController &lt; ApplicationController def new end def create user = User.find_by_email(params[:session][:email]) if user &amp;&amp; user.authenticate(params[:session][:password]) sign_in user redirect_back_or user # Sign the user in and redirect to the user's show page. else # Create an error message and re-render the signin form. flash.now[:error] = 'Invalid email/password combination' render 'new' end end ... end </code></pre> <p>My session helper:</p> <pre><code>module SessionsHelper def sign_in(user) cookies.permanent[:remember_token] = user.remember_token self.current_user = user end def signed_in? !current_user.nil? end def current_user=(user) @current_user = user end def current_user @current_user ||= User.find_by_remember_token(cookies[:remember_token]) end def current_user?(user) user == current_user end def sign_out self.current_user = nil cookies.delete(:remember_token) end def redirect_back_or(default) redirect_to(session[:return_to] || default) session.delete(:return_to) end def store_location session[:return_to] = request.url end end </code></pre> <p>Any help you can give would be brilliant! It seems like <code>session.delete()</code> simply isn't working.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload