29

These are the instructions to add a module to an existing Devise install: https://github.com/plataformatec/devise/wiki/How-To:-change-an-already-existing-table-to-add-devise-required-columns

But I can't seem to locate the necessary columns for timeoutable.

I looked for the fields that timeoutable requires in the Devise library: https://github.com/plataformatec/devise/blob/master/lib/devise/schema.rb - but there is no such method in that schema file.

The model just has a custom method with no reference to the columns: http://rdoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable

How do I add that functionality?

Thanks.

marcamillion
  • 32,933
  • 55
  • 189
  • 380

4 Answers4

29

You only need add timeoutable to your user model:

devise :timeoutable

And set the interval time in config/initializers/devise.rb:

# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
config.timeout_in = 30.minutes
monteirobrena
  • 2,562
  • 1
  • 33
  • 45
  • 2
    You also need to ensure you've run the correct migration to add the column to the database. – Ryan Drake Mar 26 '15 at 01:57
  • 9
    :timeoutable doesn't require any extra columns. See answer above. – colsen Oct 13 '15 at 07:40
  • I tried to put it right away, but looking at the code I see that the column last_request_at is read so if you don't have it you won't be able to use it. – Lomefin May 23 '17 at 23:03
28

timeoutable refers to the login session timeout. No extra columns are needed, just add it to your model.

The timeoutable hook contains all the magic (source: https://github.com/plataformatec/devise/blob/master/lib/devise/hooks/timeoutable.rb)

rdvdijk
  • 4,400
  • 26
  • 30
0

Just add to your model:

devise :timeoutable, timeout_in: XX.minutes

replace XX with the number of minutes you want.

Pshemski
  • 119
  • 1
  • 9
0

timeoutable not working if you are have remember_me = true

https://github.com/plataformatec/devise/blob/master/lib/devise/hooks/timeoutable.rb#L26

Nazar Hlynskyi
  • 109
  • 1
  • 4