Hello!
Rails 4.2.1
Devise 3 5 1
I turn on option ":timeoutable".
And I uncomment option in "config/initializers/devise.rb"
config.timeout_in = 30.minutes
config.expire_auth_token_on_timeout = true
I get this error
undefined method `ago' for 1800:Fixnum
Extracted source (around line #30):
def timedout?(last_access)
return false if remember_exists_and_not_expired?
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
end
def timeout_in
Rails.root: /home/glafir/RoR/ic-glafir
Application Trace | Framework Trace | Full Trace
devise (3.5.1) lib/devise/models/timeoutable.rb:30:in timedout?'
devise (3.5.1) lib/devise/hooks/timeoutable.rb:21:inblock in
What can do it?
Can you please provide a sample application that reproduces the error?
+
We had the same issue, it looks to be a change in the behavior (i.e. removal) of Numeric#ago in ActiveSupport 4.2.
In 4.1.7 you get the following warning:
DEPRECATION WARNING: Calling #ago or #until on a number (e.g. 5.ago) is deprecated and will be removed in the future, use 5.seconds.ago instead. (called from ago at /ruby_gems/2.0/gems/activesupport-4.1.7/lib/active_support/core_ext/numeric/time.rb:66)
And in 4.2 you get the error above.
The simplest solution for us was to change our Devise::Model's initialization call to include .seconds:
new({
id: id,
access_token: access_token,
refresh_token: refresh_token,
timeout_in: timeout_in,
scopes: scopes
})
to
new({
id: id,
access_token: access_token,
refresh_token: refresh_token,
timeout_in: timeout_in.seconds,
scopes: scopes
})
/cc @paveldruzyak @glafir
@bigtiger thanks
The simplest solution for us was to change our Devise::Model's initialization call to include .seconds:
Sorry, I don`t understand. Where to write it in?
@glafir the basic idea is that the value you're providing for timeout_in is being converted to a Fixnum. In our case it was caused by some DateTime arithmetic, e.g.
timeout_in = auth.credentials.expires_at - Time.now.to_i
Without seeing your code it's hard to say exactly what your fix needs to be. As @lucasmazza said, an example that reproduces the error would be very helpful.
I have done it so
in lib/devise/model/timeoutable in block "def timedout?(last_access)"
!timeout_in.nil? && last_access && last_access <= Time.now - timeout_in.seconds
I had this issue as well after upgrading Rails to 4.2.6 and I re-opened the Numeric class and solved this way(For example: You can add fixnum.rb with the following code into config/initializers folder):
class Numeric
def ago
self.seconds.ago
end
end
I created a PR that fixes the issue -- so maybe you can 👍 it or something to show interest in it being merged. I don't think we should be needing to monkey patch Numeric when ActiveSupport already has a solution (use #seconds.ago). https://github.com/plataformatec/devise/pull/4234
Most helpful comment
I had this issue as well after upgrading Rails to 4.2.6 and I re-opened the Numeric class and solved this way(For example: You can add fixnum.rb with the following code into config/initializers folder):