问题
Model:
devise :database_authenticatable, :registerable,:timeoutable, :recoverable, :rememberable, :trackable, :validatable,:timeout_in => 10.seconds
development.rb:
config.timeout_in = 10.seconds
devise.rb:
config.timeout_in = 10.seconds
回答1:
Are you expecting the page to refresh and show you a login page again? If so, that's not how the timeoutable feature works. If you're expecting it to present you with the login page when you refresh, remove the timeout part from your model and put the following in devise.rb NOT development.rb. Don't forget to restart rails server.
config.timeout_in = 1.hour
This is all documented in the devise wiki here
Also, I'm not sure about the logic behind 10 seconds?? Seems a little too short. If it's still not working, increase to (for example) five minutes and test.
回答2:
Also it's possible to set timeout_in option dynamically
class User < ActiveRecord::Base
devise (...), :timeoutable
def timeout_in
if self.admin?
1.year
else
2.days
end
end
end
来源:https://stackoverflow.com/questions/10495390/how-to-configure-time-out-using-devise