Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Devise: rememberable?

I'm making a Rails App.
I'd like to implement a check box 'remember me' for users to skip enter password from next time with using Devise:rememberable.but I can't figure out how to implement.
if you have any idea with this , please show me some sample code for that.

like image 578
Tai Avatar asked Aug 04 '12 17:08

Tai


People also ask

How does devise Rememberable work?

Rememberable manages generating and clearing token for remembering the user from a saved cookie. Rememberable also has utility methods for dealing with serializing the user into the cookie and back from the cookie, trying to lookup the record based on the saved information.

How does devise Current_user work?

current_user works by storing id of current user in the application session. Most commonly session is stored in cookies. Whether or not the cookies survive browser restart depends on client's browser settings.


1 Answers

Add the :rememberable option in your User model

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,
         :validatable, :token_authenticatable, :lockable, :omniauthable

  # ...

end

Create a migration to add the remember_created_at column in the table of users

class AddRememberCreatedAtToUsers < ActiveRecord::Migration
  def change
    add_column :users, :remember_created_at, :datetime
  end
end

If you're not using the Devise default views, add the checkbox to your view:

<%= f.check_box :remember_me %> <%= f.label :remember_me %>

I think that's all you need...

like image 83
Baldrick Avatar answered Sep 20 '22 05:09

Baldrick