如何将Devise的“timeoutable”模块添加到现有的Devise安装中?- Rails 3.1

29
以下是添加模块到现有 Devise 安装的说明:https://github.com/plataformatec/devise/wiki/How-To:-change-an-already-existing-table-to-add-devise-required-columns,但我似乎找不到 timeoutable 所需的必要列。我在 Devise 库中查找了 timeoutable 所需的字段:https://github.com/plataformatec/devise/blob/master/lib/devise/schema.rb,但在该模式文件中并没有这样的方法。该模型只有一个自定义方法,并未提及列:http://rdoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable。我应该如何添加此功能呢?谢谢。

你的第一个链接给出了所有答案!谢谢。 - carbonr
4个回答

29

你只需要在用户模型中添加timeoutable

devise :timeoutable

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

2
你还需要确保已运行正确的迁移以将该列添加到数据库中。 - Ryan Drake
9
timeoutable不需要任何额外的列。请参见上面的答案。 - colsen
我试图立即解决它,但是看到代码后,我发现最后请求时间列(last_request_at)被读取,所以如果你没有该列,就无法使用它。 - Lomefin

28

5
不需要列,因为用户上次请求的时间已存储在会话中。 - Jared Beck

0

只需在您的模型中添加:

devise :timeoutable, timeout_in: XX.minutes

请将 XX 替换为您想要的分钟数。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接