【问题标题】:rails - running production mode locally = No such file to load - config/environmentrails - 在本地运行生产模式 = 没有要加载的文件 - 配置/环境
【发布时间】:2014-03-24 06:06:31
【问题描述】:

我正在尝试以生产模式在本地运行:

$ RAILS_ENV=production rails s

但我明白了:

/home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/li
b/active_support/dependencies.rb:306:in `rescue in depend_on': No such file
 to load -- /home/durrantm/Dropnot/webs/rails_apps/linker/app/assets/../con
fig/environment (LoadError)

我可以创建一个全新的rails 3.1.8 应用程序并执行RAILS_ENV=production rails server,但我没有遇到这个问题。

我也可以 rails s 并且在开发模式下运行服务器正常而不会出错。

我也可以 RAILS_ENV=development rails s 并且在开发模式下运行服务器正常而不会出错。

fwiw,我的应用程序最初是一个 rails 2.3 应用程序,所以也许我遗漏了在 rails 中添加或更改的内容?

我确实有带有environment.rb 文件的config 目录。也许它被引用的方式是错误的?

我在config/application.rb 中添加了config.assets.enabled = true,但它没有帮助(没想到它是资产编译,但这是我发现的不同之处!)。

完整跟踪:

durrantm@Castle2012:~/Dropnot/webs/rails_apps/linker/config/environments (v3.1.8_with_assets)
$ RAILS_ENV=production rails s
=> Booting WEBrick
=> Rails 3.1.8 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:306:in `rescue in depend_on': No such file to load -- /home/durrantm/Dropnot/webs/rails_apps/linker/app/assets/../config/environment (LoadError)
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:301:in `depend_on'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:214:in `require_dependency'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/engine.rb:417:in `block (2 levels) in eager_load!'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/engine.rb:416:in `each'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/engine.rb:416:in `block in eager_load!'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/engine.rb:414:in `each'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/engine.rb:414:in `eager_load!'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/application/finisher.rb:51:in `block in <module:Finisher>'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/initializable.rb:30:in `instance_exec'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/initializable.rb:30:in `run'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/initializable.rb:54:in `each'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/initializable.rb:54:in `run_initializers'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/application.rb:96:in `initialize!'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /home/durrantm/Dropnot/webs/rails_apps/linker/config/environment.rb:5:in `<top (required)>'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:240:in `require'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:240:in `block in require'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:223:in `block in load_dependency'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:640:in `new_constants_in'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:223:in `load_dependency'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:240:in `require'
        from /home/durrantm/Dropnot/webs/rails_apps/linker/config.ru:4:in `block in <main>'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
        from /home/durrantm/Dropnot/webs/rails_apps/linker/config.ru:1:in `new'
        from /home/durrantm/Dropnot/webs/rails_apps/linker/config.ru:1:in `<main>'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/rack-1.3.6/lib/rack/builder.rb:40:in `eval'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/rack-1.3.6/lib/rack/builder.rb:40:in `parse_file'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/rack-1.3.6/lib/rack/server.rb:200:in `app'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/commands/server.rb:46:in `app'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/rack-1.3.6/lib/rack/server.rb:301:in `wrapped_app'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/rack-1.3.6/lib/rack/server.rb:252:in `start'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/commands/server.rb:70:in `start'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/commands.rb:54:in `block in <top (required)>'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/commands.rb:49:in `tap'
        from /home/durrantm/.rvm/gems/ruby-1.9.3-p194@linker/gems/railties-3.1.8/lib/rails/commands.rb:49:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

【问题讨论】:

  • 有些奇怪。它正在寻找app/ 目录中的config/ 目录。它不应该在那里看。
  • 是的,这肯定是奇怪的部分......
  • 是什么原因造成的?这是一个我已经运行了几年的应用程序,并通过几个 Rails 版本进行了升级,并且没有遇到过这样的问题。我目前正在通过config/ 目录(现在我正在通过initializers/ 但还没有看到任何东西......
  • 您是否正在尝试从 2 升级到 3?或者你有它在 3 上工作吗?
  • 我让它在 Rails 3.1.8 上工作,但没有资产编译。我现在正试图让它与资产编译一起工作。该应用程序本身最初是在 Rails 2.3.8 左右开始的。

标签: ruby-on-rails ruby ruby-on-rails-3 production-environment


【解决方案1】:

似乎您的旧assets 目录位于其他地方(可能在public),现在它位于app/assets,但它不知道它并且一些文件尝试加载environment.rb。只需仔细检查资产目录。

【讨论】:

  • 是的,资产以前只是在public/ 中。我已将它们移至 /app/assets/ 我尝试执行 rake assets:precompile 但它没有像我预期的那样创建 /public 结构..
  • 啊,添加公共目录很重要。一旦我添加了该目录,rake assets:precompile然后能够将资产复制到public/assets 目录。不幸的是,当我执行RAILS_ENV=production rails s 时,这个仍然 给出了No such file to load -- /home/durrantm/Dropnot/webs/rails_apps/linker/app/assets/../config/environment (LoadError) 消息。咕咕咕!
  • 顺便说一句“仔细检查资产目录”,当然,还有...?
  • 你应该调试看看哪些依赖尝试加载config/environment)
  • 如何调试?我尝试了 `RAILS_ENV=production rails s --debug 但它似乎没有进入调试模式。还有如何设置断点?似乎 Rails 启动将涉及数千行代码,我不确定我是否能够处理。
【解决方案2】:

改变了一些东西。其中一个主要目的是在尝试在本地(仅)运行静态资产时在 config/environments/production.rb 中本地启用静态资产,并在推送到生产 Web 服务器之前将其还原。我不知道。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 1970-01-01
    • 2020-10-22
    • 2011-12-17
    • 2016-10-22
    • 1970-01-01
    • 2021-05-22
    相关资源
    最近更新 更多