2017-01-17 60 views
8

Próbuję naprawić ten błąd przez jakiś czas, nie znajdując żadnej pomocy, proszę o pomoc.Błąd podczas próby załadowania urządzenia gem. ActiveSupport: Czas trwania nie może być wymuszony na Integer

Próbuję uruchomić migracje w mojej aplikacji ROR za pomocą gem devise. Ale dostaję błąd z ActiveSupport "Duration nie może być wymuszony na Integer". stało się to wtedy próbuję uruchomić:

rake db:migrate 

Nie jestem pewien, czy to ma coś wspólnego z kodem na migracje czy to jest coś o nowej wersji opracować. To jest komunikat o błędzie:

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

Używam:

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

Proszę dać mi znać, jak mogę zrobić to lepiej pytanie. pozdrowienia.

Edit: Jest to jeden z plików migracje:

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 

Również podczas próby bundle exec rake db: migrować mam prawie takie same:

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) 
+0

Czy używasz 'bundle exec rake db: migrate' lub po prostu' rake db: migrate'? – virtuexru

+2

Czy możesz opublikować plik migracji? –

+0

@virtuexru Właśnie uruchamiam db użytkownika db: migracja, ale otrzymuję te same dane wyjściowe, gdy próbuję db pakietu exec: migrate. – Sam

Odpowiedz

6

Zmierzyłem się z tym wczoraj, podczas gdy tory 3.2 i ruby ​​2.4 pracowały razem. Naprawiłem to przez małpę łatającą bibliotekę activesupport, na której leży problem.

rozwiązanie: zmienić kolejność mnożenia, umieścić pierwszy

Dołącz następujący kod w swoim szyn inicjalizatorów Duration:

# 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 
0

Spróbuj uruchomić bundle exec rake db:migrate i daj mi znać wynik. Nie mając przed sobą numeru bundle exec, nie będzie wiedział, które klejnoty, z których należy korzystać, będą używać rodzimych (systemowych) klejnotów.

Spróbuj także uruchomić program bundle update, a następnie ponownie uruchomić migrację.

+0

Dzięki za odpowiedź Virtuexru, wypróbowałem aktualizację pakietu i po tym pakiecie exec rake db: migrate, ale wynik jest prawie taki sam. Edytowałem post. – Sam

+0

Czy możesz usunąć wersję dla 'devise' w gemfile? Znaczenie ma to: gem 'devise' i uruchom 'bundle' najpierw przed uruchomieniem' bundle exec rake db: migrate' – virtuexru

+0

Czy masz również zainstalowane 'nodejs'? Możesz go potrzebować. – virtuexru

15

obliczu problemu dzisiaj podczas próby uaktualnienia starą aplikację do szyn 4.

Problem jest wersja Ruby (2.4.0), a nie wymyślać sobie. Rozważ użycie ruby-2.3.3 lub niższego i działa jak urok!

+3

Tak, właśnie to zrobiłem Rails 3.2 nie jest obsługiwany w Ruby 2.4, więc musiałem użyć niższej wersji – Bot

+0

dzięki @Mikhail Nikalyukin! Spróbuję to;) – Sam

+1

To działa dla mnie! Dziękuję Ci. Muszę zaktualizować Rails 4 do Rails 5. Ale użyłem ruby-2.3.3. – AntonAL

0

Przełącz na szynach wersji co najmniej 5.0.2, usunąć Gemfile.lock i uruchom bundle update.

+0

Dlaczego 5.0.2? '1.day' działa dobrze dla mnie na Ruby 2.4.2 i Railsach 4.2.10. Oryginalny plakat doświadczył błędu w Rails 4.1.1. Więc problem został rozwiązany między tymi wersjami. –

-1

Dziś miałem do czynienia z tym samym problemem, ale różne wersje, moja wersja ruby ​​2.4.2 i wersja 4.0.13 szyn.

Otrzymałem ten sam błąd i naprawiłem go teraz. Dzięki @ thomas-dziedzic.

Rozwiązaniem jest:

  1. Wyciągnąłem z https://github.com/rails/rails/commit/32f215c3014e580e512db5e8772d0deadf3d6497
  2. edytowany według tego linka następnie edytować https://github.com/rails/rails/blob/32f215c3014e580e512db5e8772d0deadf3d6497/activesupport/lib/active_support/core_ext/numeric/conversions.rb

Kiedy edycji active_support problem naprawił.