开发者

Setting session length with Devise

My sessions with devise timeout after 1-3 hours of non-use (not sure exactly how long). How can I adjust this?

I've looked over the docs and can't seem to find a setting for 开发者_Python百科this.


Look in config/initializers/devise.rb. There are a lot of configuration settings including config.timeout_in. The default in my version is 30 minutes. You can also set it on the model itself:

class User < ActiveRecord::Base
  devise :timeoutable, :timeout_in => 15.minutes

You can now also set the timeout dynamically.


With Rails4, the better thing to follow is:

In models/user.rb: Add :timeoutable to already existing list of devise modules.

class User < ActiveRecord::Base
  devise :timeoutable
end

In config/initializers/devise.rb: Set the timeout parameter.

Devise.setup do |config|
  config.timeout_in = 3.hours
end


Global:

class User < ActiveRecord::Base
  devise (...), :timeoutable
end

Devise.setup do |config|
  config.timeout_in = 3.hours
end

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜