私はこのエラーをしばらくの間修正しようとしていますが、役に立たないので助けてください。
Devise gemを使用して、RORアプリで移行を実行しようとしています。しかし、ActiveSupportから「DurationをIntegerに強制できません」というエラーが表示されます。これが起こった後、実行しようとしました:
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/.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)
私が使用しています:
Ruby '2.4.0'
gem 'Rails', '4.1.1'
gem 'devise', '~> 4.2.0'
これをより良い質問にする方法を教えてください。ご挨拶。
編集:これはマイグレーションファイルの1つです:
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 `<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)
Rails 3.2とRuby 2.4が一緒に動作している)を取得しているときに私は昨日これに直面しました。問題のある場所であるactivesupportライブラリにモンキーパッチを当てることで修正しました。
解決策:乗算の順序を切り替え、期間を最初に置く
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
古いアプリをRails 4.にアップグレードしようとしているときに、この問題に直面しました。
問題はRuby version(2.4.0)であり、それ自体を工夫するものではありません。Ruby-2.3.3以下を使用することを検討してください。これは魅力のように動作します!
bundle exec rake db:migrate
を実行してみて、出力を知らせてください。前にbundle exec
がないと、どのgemを使用するかわからず、ネイティブ(システム)gemを使用します。
また、bundle update
を実行してから、移行を再実行してみてください。
実際、私はこれらの条件下でactiveadmin
をインストールして実行しようとすると同じ問題が発生しました:
Rails 3.2.22.5 Ruby 2.3.8
Thomasによるソリューション は、アプリケーションが起動する前にActiveSupportが呼び出されたため、完全には機能しませんでした。
うまくいった解決策:ActiveSupportを別のgemとして抽出しました forked it 、Thomasによる上記のパッチを適用し、Railsの外でgemとして実行できるようにいくつかの追加の修正を行いました。また、activeadmin
の前にこのgemを追加したので、Duration
が必要な場合は、パッチを当てたバージョンを実行します。
# Gemfile extract
gem 'activesupport', :git => 'git://github.com/beshur/activesupport.git'
gem 'activeadmin', '0.6.6'
次に、herokuアプリをスタックheroku-16( スタックの詳細はこちら )を使用するように切り替えましたが、それでもRuby 2.3.8。
それはすでに古いバージョンですが、後で誰かを助けることを願っています。
Railsバージョン5.0.2以上に切り替え、Gemfile.lockを削除してbundle update
を実行します。
5.2.0
は最新で、18年4月9日にリリースされました。
レガシーアプリを移行するときにも同じ問題が発生しました。 Rails= 4.2にアップグレードしたら、Rubyバージョンを2.4にアップグレードし、両方のRails =およびRuby。
Gemfileでbootboot gemを使用することをお勧めします。これにより、Gitブランチを切り替えることなく、環境変数のみで新旧のバージョンRails=でスペックの実行をテストできます。