I hope you can help, have been struggling with this one for a while now :| Im using devise and Rails 3
When I click on Sign In, I get the devise Sign In page, I punch in the username and pw and click login.
After I clicked login I get redirected to the main page but now I still see the Sign In link, wich means that <% if user_signed_in? %> is still false. But it seems that there is some values in the session variable after I logged in, what is going on here? I have been using devise for some time and havent had any problems before. Thank guys!
<%= session %>
no value
<% if user_signed_in? %>
**is false**
After I logged in with devise
<%= session %>
_csrf_tokenAMUwVLu6G6rWfKICB43PYApFsYFRjVyJDSc2oU88uEk=warden.user.user.keyUser342$2a$10$.zslfggeUqvq.m/5LNSolOsession_id0db80c26bc36a4c1c74c223655dcb092
<% if user_signed_in? %>
**is false**
EDIT:
my routes.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
I think I found my problem in one of my controllers
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
after I removed this block it seemed to work perfectly :)
Devise has a concept of "scopes" so that you can sign in multiple types of users simultaneously, e.g. an admin user and a regular user. To check if a user of any scope is signed in, use signed_in?
. The scopes are defined by the naming of the model class and the routes.rb
file. Be sure they match. Can you post both? To test this out you can also try an integration test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With