An error occurred while trying to load the gem. ActiveSupport: Duration cannot be forced into Integer

I’ve been trying to fix this error for a while without finding useful information, please help.

I am trying to start a migration in my ROR application using a gem. But I get an error from ActiveSupport "Duration cannot be forced into Integer." this happened, then I will try to run:

rake db:migrate 

I'm not sure if this has anything to do with code when porting or if it is something new in the development version. This error message is:

 /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/values/time_zone.rb:285: warning: circular argument reference - now /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/thread_safe-0.3.5/lib/thread_safe/cache.rb:155: warning: constant ::Fixnum is deprecated rake aborted! Bundler::GemRequireError: There was an error while trying to load the gem 'devise'. Gem Load Error is: ActiveSupport::Duration can't be coerced into Integer Backtrace for gem load error is: /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/core_ext/numeric/time.rb:50:in `*' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/core_ext/numeric/time.rb:50:in `days' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/core_ext/numeric/time.rb:55:in `weeks' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/devise-4.2.0/lib/devise.rb:121:in `<module:Devise>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/devise-4.2.0/lib/devise.rb:9:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `block (2 levels) in require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `each' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `block in require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `each' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler.rb:106:in `require' /home/sam/aplicaciones/pess/config/application.rb:7:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require' /home/sam/aplicaciones/pess/Rakefile:4:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:687:in `raw_load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:96:in `block in load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:95:in `load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:79:in `block in run' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `load' /home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `<main>' Bundler Error Backtrace: /home/sam/aplicaciones/pess/config/application.rb:7:in `<top (required)>' /home/sam/aplicaciones/pess/Rakefile:4:in `<top (required)>' TypeError: ActiveSupport::Duration can't be coerced into Integer /home/sam/aplicaciones/pess/config/application.rb:7:in `<top (required)>' /home/sam/aplicaciones/pess/Rakefile:4:in `<top (required)>' (See full trace by running task with --trace) 

I use:

 ruby '2.4.0' gem 'rails', '4.1.1' gem 'devise', '~> 4.2.0' 

Please let me know how I can make this issue better. greetings.

Edit: This is one of the migration files:

 class DeviseCreateUsers < ActiveRecord::Migration def change create_table(:users) do |t| t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" t.string :reset_password_token t.datetime :reset_password_sent_at t.datetime :remember_created_at t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip t.string :last_sign_in_ip t.timestamps end end end 

Also, when I try bundle exec rake db: migrate, I get almost the same thing:

 bundle exec rake db:migrate /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/values/time_zone.rb:285: warning: circular argument reference - now /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/thread_safe-0.3.5/lib/thread_safe/cache.rb:155: warning: constant ::Fixnum is deprecated rake aborted! Bundler::GemRequireError: There was an error while trying to load the gem 'devise'. Gem Load Error is: ActiveSupport::Duration can't be coerced into Integer Backtrace for gem load error is: /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/core_ext/numeric/time.rb:50:in `*' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/core_ext/numeric/time.rb:50:in `days' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-4.1.1/lib/active_support/core_ext/numeric/time.rb:55:in `weeks' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/devise-4.2.0/lib/devise.rb:121:in `<module:Devise>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/devise-4.2.0/lib/devise.rb:9:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `block (2 levels) in require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `each' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `block in require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `each' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `require' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler.rb:106:in `require' /home/sam/aplicaciones/pess/config/application.rb:7:in `<top (required)>' /home/sam/aplicaciones/pess/Rakefile:4:in `require' /home/sam/aplicaciones/pess/Rakefile:4:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:687:in `raw_load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:96:in `block in load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:95:in `load_rakefile' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:79:in `block in run' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `load' /home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in `run' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in `exec' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in `dispatch' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in `start' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/exe/bundle:34:in `block in <top (required)>' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors' /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `load' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `<main>' Bundler Error Backtrace: /home/sam/aplicaciones/pess/config/application.rb:7:in `<top (required)>' /home/sam/aplicaciones/pess/Rakefile:4:in `require' /home/sam/aplicaciones/pess/Rakefile:4:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `load' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `<main>' TypeError: ActiveSupport::Duration can't be coerced into Integer /home/sam/aplicaciones/pess/config/application.rb:7:in `<top (required)>' /home/sam/aplicaciones/pess/Rakefile:4:in `require' /home/sam/aplicaciones/pess/Rakefile:4:in `<top (required)>' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `load' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `<main>' (See full trace by running task with --trace) 
+12
ruby ruby-on-rails devise activesupport
source share
7 answers

I came across this yesterday, getting rails 3.2 and ruby ​​2.4, working together. I fixed this by decapitating the activesupport library in which the problem is.

solution: switch the order of multiplication, put Duration first

Include the following code in the rail 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 
+13
source share

Today I encountered a problem when trying to upgrade an old application to rails 4.

The problem is the ruby ​​version (2.4.0), and not the development itself. Think about using ruby-2.3.3 or lower and it will work like a charm!

+21
source share

Try running bundle exec rake db:migrate and let me know the result. Without bundle exec in front, he will not know which stones to use and will use native (system) gems.

Also try running bundle update and then restart the migration.

0
source share

Switch to rails version at least 5.0.2, delete your Gemfile.lock and run bundle update .

5.2.0 is the latest version released on April 9, 18.

0
source share

Actually, I had the same problem when trying to install and run activeadmin under the following conditions:

rails 3.2.22.5 ruby ​​2.3.8

The solution from Thomas did not work completely for me, because ActiveSupport was called before the application could start.

The solution that worked for me: I extracted ActiveSupport as a separate gem, decomposed it , applied the above patch from Thomas, and made several additional corrections so that it could be run as a gem outside the rails. I also added this gem to activeadmin , so when Duration required, it launched my patched version:

 # Gemfile extract gem 'activesupport', :git => 'git://github.com/beshur/activesupport.git' gem 'activeadmin', '0.6.6' 

Then I switched my heroku application to use the heroku-16 stack ( more on the stacks here ), however ruby ​​2.3.8 is still required for it.

Hope this helps someone later, although these are already outdated versions.

0
source share

I had the same problem when porting an outdated application. By upgrading Rails to 4.2, you can upgrade from Ruby to 2.4, and then continue on the upgrade path with Rails and Ruby.

I recommend using the bootboot gem in your Gemfile so that you can only test the specifications in older and newer versions of Rails using an environment variable, without having to switch Git branches.

0
source share

Today I ran into the same problem, but with different versions, with ruby ​​version 2.4.2 and with rails version 4.0.13.

I was getting the same error and fixed it now. Thanks @ thomas-dziedzic.

Decision:

When editing active_support, the problem is fixed.

-one
source share

All Articles