Error while trying to load the gem 'devise. ActiveSupport: Duration can't be coerced into Integer

Faced the issue today while trying to upgrade old app to rails 4.

The issue is ruby version(2.4.0) and not devise itself. Consider to use ruby-2.3.3 or lower and it's going to work like a charm!


I faced this yesterday while getting rails 3.2 and ruby 2.4 working together. I fixed it by monkey patching the activesupport library which is where the problem lies.

solution: switch the order of multiplication, put Duration first

Include the following code in your rails initializers:

# pulled from https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/core_ext/numeric/time.rb

class Numeric
  def days
    ActiveSupport::Duration.new(24.hours * self, [[:days, self]])
  end
  alias :day :days

  def weeks
    ActiveSupport::Duration.new(7.days * self, [[:days, self * 7]])
  end
  alias :week :weeks

  def fortnights
    ActiveSupport::Duration.new(2.weeks * self, [[:days, self * 14]])
  end
  alias :fortnight :fortnights
end

# pulled from https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/core_ext/integer/time.rb

class Integer
  def months
    ActiveSupport::Duration.new(30.days * self, [[:months, self]])
  end
  alias :month :months

  def years
    ActiveSupport::Duration.new(365.25.days * self, [[:years, self]])
  end
  alias :year :years
end