I am building an app in which I would like the users to automatically be remembered on their computers, without having a \"remember me\" check box.
I read that I may
I think customizing your devise controller is the way to go here.
Goal: automatically set remember-me for everybody.
First, create a devise sessions controller. Let's tell rails routes about it
config/routes.rb
devise_for :users, :controllers => {:sessions => 'sessions'}
app/controllers/sessions_controller.rb
class SessionsController < Devise::SessionsController
def create
params[:user].merge!(remember_me: 1)
super
end
end
This way, the user's remember me will always be set to true. yay!
You'll then want to edit the login form to not display the remember_me checkbox.
Also, change this in the initializer to something far off:
#config.remember_for = 2.weeks
config.remember_for = 1.year
That should be a persistent option so you can do this on an after create hook for the user since you want it to be a permanent option.
If you read this pull request in devise: https://github.com/plataformatec/devise/issues/1513, the sanctioned way to remember by default appears to simply define on your User class:
class User
def remember_me
(super == nil) ? true : super
end
end