Koudoku 在本地运行良好,但在 Heroku 上崩溃
Koudoku runs fine locally but crashes on Heroku
我最近安装了 Koudoku gem,它在我的电脑上运行良好,但是当我现在推送到 heroku 时,应用程序出现错误,日志如下所示。有谁知道为什么我收到有关 application_helper 的错误消息?我的项目中通常没有该特定文件,但我相信 Koudoku 引擎会在运行时添加它。感谢您的帮助!
编辑:我没有答案,但我怀疑这可能是由于引擎的初始化方式所致。我在 config/application.rb 文件中设置了以下行:
config.assets.initialize_on_precompile = 假
我认为这可能会阻止初始化程序加载,除非我根据此博客 post 向我的 lib/engine.rb 添加一些内容:
http://octothought.com/precompiling-assets-for-a-rails-engine-on-heroku/
任何人都可以帮助我了解如何调整他们添加到 engine.rb 的代码以适应我的情况吗?他们说:"The magic incantation for that is to pass a special :group => :assets or :group => :all option to your engine’s initializer, and make sure you configure your precompiled in that initializer." 但在实际代码中他们谈论的火箭发动机让我感到困惑。
initializer "RocketEngine asset precompile", :group => :all do |app|
app.config.assets.precompile += %w(
rocket.css
rocket.js
)
end
这是我在 heroku 上的实际错误:
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `bin/rails server -p 54469 -e production`
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:144:in `modules_for_helpers'
app[web.1]: => Booting WEBrick
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/bundler/gems/koudoku-9e73e64e5520/app/controllers/koudoku/application_controller.rb:4:in `<class:ApplicationController>'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/engine.rb:465:in `each'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:308:in `depend_on'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/engine.rb:467:in `block in eager_load!'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `tap'
app[web.1]: from bin/rails:8:in `<main>'
app[web.1]: Exiting
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:148:in `block in modules_for_helpers'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:248:in `require'
app[web.1]: from /app/config.ru:3:in `block in <main>'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
app[web.1]: from bin/rails:8:in `require'
app[web.1]: => Run `rails server -h` for more startup options
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:108:in `helper'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:349:in `require_or_load'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/engine.rb:465:in `eager_load!'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/application/finisher.rb:56:in `each'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/server.rb:80:in `start'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands.rb:17:in `<top (required)>'
app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:151:in `rescue in block in modules_for_helpers': Missing helper file helpers/application_helper.rb (AbstractController::Helpers::MissingHelperError)
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/helpers.rb:93:in `modules_for_helpers'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/initializable.rb:30:in `run'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:248:in `block in require'
我通过将 application_helper.rb 添加到 app/helpers 解决了这个问题:
module ApplicationHelper
end
并且还在 controllers/application_controller.rb
中导入 ApplicationHelper
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include ApplicationHelper
end
我最近安装了 Koudoku gem,它在我的电脑上运行良好,但是当我现在推送到 heroku 时,应用程序出现错误,日志如下所示。有谁知道为什么我收到有关 application_helper 的错误消息?我的项目中通常没有该特定文件,但我相信 Koudoku 引擎会在运行时添加它。感谢您的帮助!
编辑:我没有答案,但我怀疑这可能是由于引擎的初始化方式所致。我在 config/application.rb 文件中设置了以下行: config.assets.initialize_on_precompile = 假 我认为这可能会阻止初始化程序加载,除非我根据此博客 post 向我的 lib/engine.rb 添加一些内容: http://octothought.com/precompiling-assets-for-a-rails-engine-on-heroku/
任何人都可以帮助我了解如何调整他们添加到 engine.rb 的代码以适应我的情况吗?他们说:"The magic incantation for that is to pass a special :group => :assets or :group => :all option to your engine’s initializer, and make sure you configure your precompiled in that initializer." 但在实际代码中他们谈论的火箭发动机让我感到困惑。
initializer "RocketEngine asset precompile", :group => :all do |app|
app.config.assets.precompile += %w(
rocket.css
rocket.js
)
end
这是我在 heroku 上的实际错误:
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `bin/rails server -p 54469 -e production`
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:144:in `modules_for_helpers'
app[web.1]: => Booting WEBrick
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/bundler/gems/koudoku-9e73e64e5520/app/controllers/koudoku/application_controller.rb:4:in `<class:ApplicationController>'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/engine.rb:465:in `each'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:308:in `depend_on'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/engine.rb:467:in `block in eager_load!'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `tap'
app[web.1]: from bin/rails:8:in `<main>'
app[web.1]: Exiting
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:148:in `block in modules_for_helpers'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:248:in `require'
app[web.1]: from /app/config.ru:3:in `block in <main>'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
app[web.1]: from bin/rails:8:in `require'
app[web.1]: => Run `rails server -h` for more startup options
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:108:in `helper'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:349:in `require_or_load'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/engine.rb:465:in `eager_load!'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/application/finisher.rb:56:in `each'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands/server.rb:80:in `start'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/commands.rb:17:in `<top (required)>'
app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/abstract_controller/helpers.rb:151:in `rescue in block in modules_for_helpers': Missing helper file helpers/application_helper.rb (AbstractController::Helpers::MissingHelperError)
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.0.beta2/lib/action_controller/metal/helpers.rb:93:in `modules_for_helpers'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0.beta2/lib/rails/initializable.rb:30:in `run'
app[web.1]: from /app/vendor/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:248:in `block in require'
我通过将 application_helper.rb 添加到 app/helpers 解决了这个问题:
module ApplicationHelper
end
并且还在 controllers/application_controller.rb
中导入 ApplicationHelperclass ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include ApplicationHelper
end