Rails 5.2无法在生产环境中加载

时间:2018-12-28 00:32:35

标签: ruby-on-rails activerecord dependencies

我正在尝试在生产环境中运行我的新应用,但出现一个奇怪的错误。

$ rails server --environment=production
=> Booting Puma
=> Rails 5.2.2 application starting in production 
=> Run `rails server -h` for more startup options
Exiting
/Users/user/.rvm/gems/ruby-2.4.1/gems/activerecord-5.2.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `has_one_attached' for #<Class:0x007fc50e4e3e70> (NoMethodError)
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activestorage-5.2.2/app/models/active_storage/blob/representable.rb:7:in `block in <module:Representable>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/concern.rb:122:in `class_eval'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/concern.rb:122:in `append_features'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activestorage-5.2.2/app/models/active_storage/blob.rb:23:in `include'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activestorage-5.2.2/app/models/active_storage/blob.rb:23:in `<class:Blob>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activestorage-5.2.2/app/models/active_storage/blob.rb:16:in `<main>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:378:in `block in require_or_load'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `block in load_interlock'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:13:in `loading'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `load_interlock'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:356:in `require_or_load'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:46:in `block in require_or_load'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:45:in `require_or_load'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:334:in `depend_on'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `depend_on'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:246:in `require_dependency'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/engine.rb:478:in `block (2 levels) in eager_load!'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/engine.rb:477:in `each'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/engine.rb:477:in `block in eager_load!'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/engine.rb:475:in `each'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/engine.rb:475:in `eager_load!'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/engine.rb:356:in `eager_load!'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/application/finisher.rb:69:in `each'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `call'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
    from /Users/user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
    from /Users/user/Projects/My App/app-name/config/environment.rb:5:in `<main>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require_relative'
    from config.ru:3:in `block in <main>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/builder.rb:55:in `initialize'
    from config.ru:in `new'
    from config.ru:in `<main>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/builder.rb:49:in `eval'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/builder.rb:40:in `parse_file'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/server.rb:319:in `build_app_and_options_from_config'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/server.rb:219:in `app'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:27:in `app'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/server.rb:354:in `wrapped_app'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/rack-2.0.6/lib/rack/server.rb:283:in `start'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:53:in `start'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:147:in `block in perform'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:142:in `tap'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:142:in `perform'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/command/base.rb:65:in `perform'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/command.rb:46:in `invoke'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<main>'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
    from /Users/user/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
    from bin/rails:4:in `<main>'

通常的谷歌搜索功能还没有出现,并提供了有用的答案。有谁知道如何在生产环境中运行它?

有趣的是,堆栈跟踪指向environment.rb的第5行,该行未更改默认值,但具有此行。

Rails.application.initialize!

当我将其注释掉时,服务器终于启动,但是一旦加载任何页面(显然),该服务器就会失败。

任何指针将不胜感激!我的应用程序中没有使用任何has_one_attached方法,所以我不确定下一步要去哪里!

2 个答案:

答案 0 :(得分:0)

小伙伴。你知道吗?看来是由于我在database.yml文件的production:部分上的配置不正确。

答案 1 :(得分:-1)

通过运行以下命令来安装活动存储:

 rails active_storage:install
 db:migrate

在模型上添加新属性,如下:

has_one_attached :image

此外,您还需要在application.rb文件中要求“ active_storage”