title: Unable to end user session in Rails
body: <p>I'm building a basic app in Rails, using Bcrypt and has_secure_password for authentication. </p>
  
  <p>I was trying to delete the User, by putting a link in the views and then the basic method in the user controller:</p>
  
  <pre><code>  def destroy
      @user.destroy
      redirect_to root_path(@user)
    end  
  </code></pre>
  
  <p>The problem is that this seems to delete the user without ending the session first, so now I am trapped in a loop wherein the error message reads: Couldn't find User with 'id'=5, because the user has been deleted. </p>
  
  <p>I have tried to kill the user session in the terminal by using: kill -9 PID, but this did not have the intended effect. It only seemed to be the same as ctrl-c. </p>
  
  <p>I would like to know how I am able to end a user session in the terminal if this should ever happen again, and how I am able to delete a user and the user session at the same time. Thank you </p>
  
  <p>PS. The sessions controller has the following methods as per Bcrypt:</p>
  
  <pre><code>def create
    user = User.find_by_email(params[:email])
     if user &amp;&amp; user.authenticate(params[:password])
      session[:user_id] = user.id
      redirect_to new_comment_path, notice: "Logged in!"
     else
      flash.now.alert = "Email or password is invalid"
      render "new"
     end
    end
  
   def destroy
    session[:user_id] = nil
    redirect_to root_url, notice: "Logged out!"
   end
  </code></pre>