【问题标题】:Rails 5.2 fails to load in Production EnvironmentRails 5.2 无法在生产环境中加载
【发布时间】:2018-12-30 01:50:17
【问题描述】:

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

$ 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 方法,所以我不确定下一步该往哪里看!

【问题讨论】:

  • 在 development.rb 中它被设置为 :local,但在生产中它被注释掉了。
  • 它是否在开发中启动?
  • 是的!运行 rails server 时从未遇到过问题

标签: ruby-on-rails activerecord dependencies


【解决方案1】:

小崽子。你知道吗?看来这是由于我在生产中的错误配置:database.yml 文件的部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    相关资源
    最近更新 更多