当前位置:  开发笔记 > 后端 > 正文

尝试加载gem'设计时出错.ActiveSupport:持续时间不能强制转换为Integer

如何解决《尝试加载gem'设计时出错.ActiveSupport:持续时间不能强制转换为Integer》经验,为你挑选了2个好方法。

我一直试图解决这个错误一段时间没有找到任何帮助,请帮助.

我正在尝试使用设计宝石在我的ROR应用上运行迁移.但我从ActiveSupport得到错误'持续时间无法强制转换为整数'.这发生了然后我尝试运行:

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 `'
/home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/devise-4.2.0/lib/devise.rb:9:in `'
/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 `'
/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 `'
/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 `'
/home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `load'
/home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `
' Bundler Error Backtrace: /home/sam/aplicaciones/pess/config/application.rb:7:in `' /home/sam/aplicaciones/pess/Rakefile:4:in `' TypeError: ActiveSupport::Duration can't be coerced into Integer /home/sam/aplicaciones/pess/config/application.rb:7:in `' /home/sam/aplicaciones/pess/Rakefile:4:in `' (See full trace by running task with --trace)

我正在使用:

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

请让我知道如何才能让这个问题更好.问候.

编辑:这是迁移文件之一:

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

此外,当尝试捆绑exec rake db:migrate时,我得到几乎相同:

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 `'
/home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/devise-4.2.0/lib/devise.rb:9:in `'
/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 `'
/home/sam/aplicaciones/pess/Rakefile:4:in `require'
/home/sam/aplicaciones/pess/Rakefile:4:in `'
/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 `'
/home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `load'
/home/sam/.rbenv/versions/2.4.0/bin/rake:22:in `'
/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 '
/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 `'
/home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `load'
/home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `
' Bundler Error Backtrace: /home/sam/aplicaciones/pess/config/application.rb:7:in `' /home/sam/aplicaciones/pess/Rakefile:4:in `require' /home/sam/aplicaciones/pess/Rakefile:4:in `' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `load' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `
' TypeError: ActiveSupport::Duration can't be coerced into Integer /home/sam/aplicaciones/pess/config/application.rb:7:in `' /home/sam/aplicaciones/pess/Rakefile:4:in `require' /home/sam/aplicaciones/pess/Rakefile:4:in `' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `load' /home/sam/.rbenv/versions/2.4.0/bin/bundle:22:in `
' (See full trace by running task with --trace)

Mikhail Nika.. 21

在尝试将旧应用程序升级到rails 4时,今天面临的问题.

问题是ruby版本(2.4.0)并没有自己设计.考虑使用ruby-2.3.3或更低版本,它将像魅力一样工作!



1> Mikhail Nika..:

在尝试将旧应用程序升级到rails 4时,今天面临的问题.

问题是ruby版本(2.4.0)并没有自己设计.考虑使用ruby-2.3.3或更低版本,它将像魅力一样工作!


是的,这就是我做的.ruby 2.4不支持Rails 3.2,因此不得不使用较低版本.

2> 小智..:

我昨天遇到了这个问题,同时让rails 3.2和ruby 2.4一起工作.我通过猴子修补activesupport库来修复它,这是问题所在.

解决方案:切换乘法的顺序,先放入Duration

在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

推荐阅读
重庆制造漫画社
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有