Rails 3 Devise Session matters, but <% if user_signed_in? %> false

I hope you can help, struggling with this for a while: | Im using devise and Rails 3

When I click "Login", I get the login page, I punch through the username and pw and find the login.

After I clicked on the login, I am redirected to the main page, but now I still see the Sign In link, which means that <% if user_signed_in? %> is still false. But it seems that there are some values ​​in the session variable after logging in, what happens here? I used it for a while and I had problems. Thanks guys!


Before I log in using
<%= session %>
no value

<% if user_signed_in? %>
**is false**

After logging in with

<%= session %>
_csrf_tokenAMUwVLu6G6rWfKICB43PYApFsYFRjVyJDSc2oU88uEk=warden.user.user.keyUser342$2a$10$.zslfggeUqvq.m/5LNSolOsession_id0db80c26bc36a4c1c74c223655dcb092

<% if user_signed_in? %>
**is false**

EDIT:

my route.rb file

Cybercellar3::Application.routes.draw do
  devise_for :users

  get "home/index"


<% if signed_in? %>
**is still false**

EDIT2:

user.rb

class User < ActiveRecord::Base
      # Include default devise modules. Others available are:
      # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
      devise :database_authenticatable, :registerable,
             :recoverable, :rememberable, :trackable, :validatable

      # Setup accessible (or protected) attributes for your model
      attr_accessible :email, :password, :password_confirmation, :remember_me
    end

,

application_controller.rb

    #facebook stuff
    def current_user
        @current_user ||= User.find_by_id(session[:user_id])
    end

    def signed_in?
        !!current_user
    end

    helper_method :current_user, :signed_in?

    def current_user=(user)
        @current_user = user
        session[:user_id] = user.id
    end
    #facebook stuff

, , :)

+5
4

"", , . . , , signed_in?. routes.rb. , . ? , .

+3

. , user_signed_in? , current_user, , , , , - .

, - - .

0

, , , ! , , .

, Devise. , current_user user_signed_in? , , session_helper.rb, , (sign_in, current_user ..), () Devise Devise lib.

, , . !

0

As Irina Nazarova said. Make sure that you do not have methods with the same name that you wrote yourself, included in your project. It would seem that Devise uses this in the first place. This is exactly what caused my problem.

0
source

All Articles