web-dev-qa-db-fra.com

Erreur lors de la tentative de chargement de la gemme. ActiveSupport: la durée ne peut pas être contrainte dans Integer

Cela fait un moment que j'essaie de corriger cette erreur sans trouver d'aide, s'il vous plaît.

J'essaie d'exécuter des migrations sur mon application ROR à l'aide de la pierre précieuse. Mais je reçois une erreur de ActiveSupport "La durée ne peut pas être forcée dans Integer". c'est arrivé alors j'essaye de courir:

rake db:migrate

Je ne suis pas sûr si cela a quelque chose à voir avec le code sur les migrations ou s'il s'agit d'une nouvelle version de carte . C'est le message d'erreur:

/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)

J'utilise:

Ruby '2.4.0'
gem 'Rails', '4.1.1'
gem 'devise', '~> 4.2.0'

S'il vous plaît laissez-moi savoir comment puis-je faire de cette question une meilleure . Salutations.

Edit: C’est l’un des fichiers de migration:

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

Aussi, en essayant bundle exec rake db: migrate Je suis presque pareil:

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)
11
Sam

J'ai fait face à cela hier en faisant travailler ensemble Rails 3.2 et Ruby 2.4. Je l'ai corrigé en appliquant un correctif à la bibliothèque activeupport sur laquelle le problème se situe.

solution: changer l'ordre de multiplication, mettre la durée en premier

Incluez le code suivant dans vos initialiseurs Rails:

# 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
10
Thomas Dziedzic

A fait face au problème aujourd'hui en essayant de mettre à niveau une ancienne application vers Rails 4.

Le problème est la version de Ruby (2.4.0) et non pas le produit lui-même. Pensez à utiliser Ruby-2.3.3 ou une version inférieure et cela fonctionnera à merveille!

21
Mikhail Nikalyukin

Essayez d'exécuter bundle exec rake db:migrate et laissez-moi savoir la sortie. Sans bundle exec devant, il ne saura pas quelles gemmes utiliser et utilisera des gems natives (système).

Essayez également d'exécuter bundle update, puis de réexécuter la migration.

0
virtuexru

En fait, j'ai eu le même problème en essayant d'installer et d'exécuter activeadmin dans ces conditions:

Rails 3.2.22.5 Ruby 2.3.8

La solution de Thomas ne fonctionnait pas pleinement pour moi, car ActiveSupport avait été appelé avant le démarrage de l'application.

Solution qui a fonctionné pour moi: J'ai extrait ActiveSupport sous forme de gem séparé, forked , appliqué le correctif ci-dessus par Thomas et effectué quelques corrections supplémentaires pour qu'il puisse être exécuté comme gem, en dehors de Rails . J'ai aussi ajouté cette gemme avant la activeadmin. Ainsi, lorsque Duration était requis, il exécutait ma version corrigée:

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

Ensuite, j'ai basculé mon application heroku pour utiliser la pile heroku-16 ( plus sur les piles ici ), mais elle nécessite toujours Ruby 2.3.8.

J'espère que cela aidera quelqu'un plus tard, même si les versions sont déjà obsolètes.

0
Alex Buznik

Passez à la version 5.0.2 de Rails au moins, supprimez votre Gemfile.lock et exécutez bundle update.

5.2.0 est le plus récent, celui-ci a été publié le 9 avril '18 ..

0
Daniel O'Quinn