How to automatically keep user remembered in Devise

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

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