How do I add Devise's 'timeoutable' module to an existing Devise install? - Rails 3.1
Asked Answered
K

4

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.

Kowalski answered 22/9, 2011 at 19:18 Comment(1)
Your first link gave all the answers! thanksOrgel
S
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)

Steele answered 22/9, 2011 at 19:54 Comment(1)
No columns are required because the time of the user's last request is stored in the session.Collotype
M
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
Musketry answered 8/10, 2014 at 14:25 Comment(3)
You also need to ensure you've run the correct migration to add the column to the database.Publicspirited
:timeoutable doesn't require any extra columns. See answer above.Pestilent
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.Bain
S
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)

Steele answered 22/9, 2011 at 19:54 Comment(1)
No columns are required because the time of the user's last request is stored in the session.Collotype
O
0

Just add to your model:

devise :timeoutable, timeout_in: XX.minutes

replace XX with the number of minutes you want.

Ocean answered 30/8, 2018 at 18:55 Comment(0)
C
0

timeoutable not working if you are have remember_me = true

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

Condillac answered 28/11, 2018 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.