Note that there are some explanatory texts on larger screens.

plurals
  1. POSignout not working rails 3.2
    primarykey
    data
    text
    <p>I've done the Michael Hartl's Tutorial and now I'm using it to build a project. For Authentication/Authorization I'm basically using the same code from the tutorial and the sample app that I built with it. In my project though the signout (destroy session) is not working. After clicking the signout link it does the redirect to the home page but it has the wrong links in the navigation and I can still access pages I shouldn't be able to (indicating that I'm still signed in) and I can't figure out what's wrong. Any ideas?</p> <p>Sessions Controller</p> <pre><code>class SessionsController &lt; ApplicationController def new render '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_to user else flash.now[:error] = 'Invalid email/password combination' render 'new' end end def destroy sign_out redirect_to root_path end end </code></pre> <p>Sessions 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 end </code></pre> <p>Header Links</p> <pre><code> &lt;header&gt; &lt;h1&gt;&lt;%= link_to image_tag('logo.gif'), root_path %&gt;&lt;/h1&gt; &lt;div id="login-sec"&gt; &lt;div class="login-row"&gt; &lt;div class="col"&gt; &lt;% if signed_in? %&gt; &lt;ul&gt; &lt;li&gt;&lt;%= link_to "Signout", signout_path, method: "delete" %&gt;&lt;/li&gt; &lt;/ul&gt; &lt;% else %&gt; &lt;ul&gt; &lt;li&gt;&lt;%= link_to "Forgot Password", "#" %&gt;&lt;/li&gt; &lt;li class="last"&gt;&lt;%= link_to "New user register here", signup_path %&gt; &lt;/li&gt; &lt;/ul&gt; &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;%= link_to image_tag('go-btn.png'), signin_path %&gt;&lt;/center&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/header&gt; </code></pre> <p>User Model (where remember token is created)</p> <pre><code>class User &lt; ActiveRecord::Base attr_accessible :company, :name, :email, :password, :password_confirmation has_secure_password before_save { |user| user.email = email.downcase } before_save :create_remember_token validates :name, presence: true, length: { maximum: 70 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } validates :password, presence: true, length: { minimum: 6 } validates :password_confirmation, presence: true private def create_remember_token self.remember_token = SecureRandom.urlsafe_base64 end end </code></pre> <p>Routes File</p> <pre><code>App::Application.routes.draw do resources :users resources :sessions, only: [:new, :create, :destroy] root to: 'static_pages#home' match '/about', to: 'static_pages#about' match '/contact', to: 'static_pages#contact' match '/signup', to: 'users#new' match '/about-yourself', to: 'users#about-yourself' match '/signin', to: 'sessions#new' match '/signout', to: 'sessions#destroy', via: :delete </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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