Skip to content

How To: Add timeout_in value dynamically

rodrigoflores edited this page Nov 25, 2011 · 11 revisions

How to: Add timeout in value dynamically

This feature is currently only on Devise master and will be released soon.

To dinamically set the timeout for each user, you can define a method in the user model called timeout_in that returns the timeout value.

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

  def timeout
    if user.admin?
      1.year
    else
      2.days
    end
  end
end

timeout should return a integer with the number of seconds (the timedout? method that devise uses, call the ago method on what timeout returns). But of course, you can use Rails 10.seconds or 1.hour to improve readability.

Clone this wiki locally