Devise remember me not storing cookie

2019-07-20 01:09发布

问题:

I've set up a simple sample app that uses devise for user authentication.

When I select the rember me checkbox on login I get the following in the console:

Processing by Devise::SessionsController#create as HTML Parameters: {"commit"=>"Sign in", "authenticity_token"=>"Vm+2aWEmCRnnjdXAOpXdI5dGChUKlEcmfGNXNoGUkwc=", "utf8"=>"Γ£ô", "user"=>{"remember_me"=>"1", "password" =>"[FILTERED]", "email"=>"test@example.com"}} ←[1m←[35mUser Load (1.0ms)←[0m SELECT "users".* FROM "users" WHERE "users"."email" = 'test@example.com' LIMIT 1 ←[1m←[36mAREL (1.0ms)←[0m ←[1mUPDATE "users" SET "last_sign_in_at" = '2011-10-06 21:36:46.439511', "updated_at" = '2011-10-06 21:43:59.298269', "sign_in_coun t" = 15, "current_sign_in_at" = '2011-10-06 21:43:59.297269' WHERE "users"."id" = 1←[0m

I have the following in my Posts controller:

before_filter :authenticate_user!

However, when I close the browser and open it again I am forced to login again before I can view posts. It doesn't seem that the cookie is being stored. I found the following cookie in firefox for my page:

Cookie Name: remember_user_token Expires: at end of session

Is this the cookie thats supposed to be stored and expire at a future date but instead expires at the end of session? Can someone verify this?

I've tried both commenting and uncommenting config.remember_for = 2.weeks in devise.rb to different settings and nothing seems to fix the problem.

My User.rb file looks like this:

class User < ActiveRecord::Base

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