Rails生成命令错误

时间:2018-02-07 09:21:13

标签: ruby-on-rails ruby

我使用Rails版本4.2.7.1和ruby 2.2.5与rvm。 捆绑更新后,我无法再运行rails g命令。 出现以下错误:

-- [](4.2)
/Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activerecord-4.2.7.1/lib/active_record/migration.rb:664:in `block in method_missing': undefined method `[]' for #<ActiveRecord::Migration:0x007fce8f996460> (NoMethodError)
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activerecord-4.2.7.1/lib/active_record/migration.rb:634:in `block in say_with_time'
    from /Users/Sergei/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/benchmark.rb:288:in `measure'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activerecord-4.2.7.1/lib/active_record/migration.rb:634:in `say_with_time'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activerecord-4.2.7.1/lib/active_record/migration.rb:654:in `method_missing'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activerecord-4.2.7.1/lib/active_record/migration.rb:416:in `method_missing'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/encrypted_store-0.3.0/lib/generators/encrypted_store/upgrade/ZeroOneFive/templates/upgrade_encryption_keys_to_015.rb:1:in `<top (required)>'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/encrypted_store-0.3.0/lib/encrypted_store/railtie.rb:18:in `block (2 levels) in <class:Railtie>'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/encrypted_store-0.3.0/lib/encrypted_store/railtie.rb:18:in `each'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/encrypted_store-0.3.0/lib/encrypted_store/railtie.rb:18:in `block in <class:Railtie>'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/railtie.rb:228:in `call'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/railtie.rb:228:in `block in run_generators_blocks'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/railtie.rb:245:in `each'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/railtie.rb:245:in `each_registered_block'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/railtie.rb:228:in `run_generators_blocks'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/application.rb:462:in `block in run_generators_blocks'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/engine/railties.rb:13:in `each'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/engine/railties.rb:13:in `each'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/application.rb:462:in `run_generators_blocks'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/engine.rb:461:in `load_generators'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:129:in `generate_or_destroy'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:50:in `generate'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

已经尝试重新安装gemset并删除所有以前的迁移文件,但它没有帮助。可能是什么原因?

1 个答案:

答案 0 :(得分:0)

OK!我自己解决了。正如我从这一行所看到的那样

from /Users/Sergei/.rvm/gems/ruby-2.2.5@rails4/gems/encrypted_store-0.3.0/lib/generators/encrypted_store/upgrade/ZeroOneFive/templates/upgrade_encryption_keys_to_015.rb:1:in `<top (required)>'

它有来自gem encrypted_store的依赖。我从Gemfile中删除了这个gem并使用bundle命令重新安装(gem'heedrated'store','〜&gt; 0.2.8')。在此之后,错误消失了。