rails 3.1, devise gem, :timeoutable is not working

2019-05-28 09:04发布

问题:

I am trying to use the auto signout feature,

here is my model:

class Student < ActiveRecord::Base

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :timeoutable

  def timeout
      3.seconds
  end
end

here is the routes.rb:

  devise_for :students do get '/students/sign_out' => 'students/sessions#destroy' end

I sign-in, then I wait 5 seconds, at this time, student session should be expired, but, if vavigating to any other protected page is not redirecting back to login form, meaning that the session is still active.

Is there something I am missing ?? what shall I check ?

Thanks, hopewise

回答1:

There is an incorrect information on devise wiki. The correct method is timeout_in.

I've fixed the wiki page https://github.com/plataformatec/devise/wiki/How-To:-Add-timeout_in-value-dynamically.



回答2:

I found the solution, the config.timeout_in was commented at the file devise.rb at config/initializers folder

I thought that adding :timeoutable is all what I have to do, I think devise.rb at config/initializers should be added to the documentation beside talking about :timeoutable, it will be helpful for RoR newbies.