为啥 heroku 在我的路由文件中运行此代码,而该代码只能在开发模式下运行?
Posted
技术标签:
【中文标题】为啥 heroku 在我的路由文件中运行此代码,而该代码只能在开发模式下运行?【英文标题】:Why is heroku running this code in my routes file that should only be run in development mode?为什么 heroku 在我的路由文件中运行此代码,而该代码只能在开发模式下运行? 【发布时间】:2015-01-31 11:18:47 【问题描述】:在我的 routes.rb 文件中,我有以下代码:
if Rails.env.development?
mount LetterOpenerWeb::Engine, at: "/letter_opener"
end
因为在开发模式下,我们喜欢让 letter_opener 为我们打开电子邮件。但是当我推到heroku时,我得到了这个(下)。为什么是这样?为什么 heroku 不忽略我的 routes.rb 中的这一部分?
感谢任何可以提供帮助的人!
捆绑完成(23.08 秒) 清理捆绑程序缓存。 -----> 为 Rails 资产管道准备应用程序 运行:耙资产:预编译 耙中止! NameError: 未初始化的常量 LetterOpenerWeb /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/config/routes.rb:43:in
block in <top (required)>' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.2/lib/action_dispatch/routing/route_set.rb:337:in
instance_exec' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.2/lib/action_dispatch/routing/route_set.rb:337:ineval_block' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.2/lib/action_dispatch/routing/route_set.rb:315:in
draw' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/config/routes.rb:1:in<top (required)>' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/routes_reloader.rb:40:in
block in load_paths' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/routes_reloader.rb:40:ineach' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/routes_reloader.rb:40:in
load_paths' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/routes_reloader.rb:16:inreload!' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/routes_reloader.rb:26:in
block in updater' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.2/lib/active_support/file_update_checker.rb:75:incall' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.2/lib/active_support/file_update_checker.rb:75:in
执行' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/routes_reloader.rb:27:inupdater' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/routes_reloader.rb:7:in
execute_if_updated' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application/finisher.rb:71:inblock in <module:Finisher>' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/initializable.rb:30:in
instance_exec' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/initializable.rb:30:inrun' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/initializable.rb:55:in
block in run_initializers' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/initializable.rb:54:inrun_initializers' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application.rb:300:in
initialize! /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/config/environment.rb:5:in<top (required)>' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application.rb:276:in
require_environment! /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/railties-4.1.2/lib/rails/application.rb:379:inblock in run_tasks_blocks' /tmp/build_91bf7616fa162d43a8d71e23aeee1e99/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:55:in
block(2 级)在定义中 任务:TOP => 环境 (通过使用 --trace 运行任务查看完整跟踪)! !预编译资产失败。
【问题讨论】:
【参考方案1】:我相信您必须指定您的运行时环境,在这种情况下您希望成为 ENV=production(根据上面输出中的请求,即“require_environment!”)。我不知道您正在运行导致此错误的命令/任务,但请尝试将上述环境变量设置为“生产”。 (我不记得你是否需要在生产这个词周围加上引号。)
【讨论】:
由于某种我不完全理解的原因,这有效。【参考方案2】:我在 rake 任务中有一行强制该任务仅在开发模式下运行。但是这条线超出了 rake 任务的范围,所以它影响了整个应用程序。
【讨论】:
以上是关于为啥 heroku 在我的路由文件中运行此代码,而该代码只能在开发模式下运行?的主要内容,如果未能解决你的问题,请参考以下文章
为啥我的 sidekiq 计划的 cron 作业没有在 heroku 上运行?