Config.cache_classes heroku 上未初始化的常量控制器
Config.cache_classes unitialized constant controller on heroku
我刚刚将我的 rails 项目从 rails 4.2 升级到 rails 5.1.4。升级后我的主控制器开始崩溃。当我调用它时,它会在路由文件上抛出一个错误,指出“未初始化的主控制器”
搜索了很长时间后,我在我的 heroku 服务器上将 config.cache_classes 设置为 false,突然一切正常。虽然我无法在我的本地环境中重现逻辑。
任何人都知道在哪里搜索修复程序或如何修复此问题?我已经搜索了好几天,但没有找到它可能是什么!
很高兴提供任何人认为有用的详细信息以提供帮助!问就是了!
Ruby 版本 2.4.2
** 编辑 - 根据要求添加信息 **
完整错误是:
ActionController::RoutingError (uninitialized constant HomeController):
2017-11-26T15:16:55.051341+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in `const_get'
2017-11-26T15:16:55.051342+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in `block in constantize'
2017-11-26T15:16:55.051343+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in `each'
2017-11-26T15:16:55.051343+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in `inject'
2017-11-26T15:16:55.051344+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in `constantize'
2017-11-26T15:16:55.051345+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:582:in `get'
2017-11-26T15:16:55.051346+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:613:in `constantize'
2017-11-26T15:16:55.051346+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/http/request.rb:85:in `controller_class_for'
2017-11-26T15:16:55.051347+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/http/request.rb:78:in `controller_class'
2017-11-26T15:16:55.051348+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:43:in `controller'
2017-11-26T15:16:55.051348+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:29:in `serve'
2017-11-26T15:16:55.051349+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:50:in `block in serve'
2017-11-26T15:16:55.051350+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `each'
2017-11-26T15:16:55.051350+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `serve'
2017-11-26T15:16:55.051351+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:834:in `call'
控制器基于/myapp/app/HomeController.rb
class HomeController < ActionController::API
def click
# Execution of method, removed to keep post small
end
end
/myapp/config 文件夹中的路由文件如下所示:
Rails.application.routes.draw do
# root is set to a explainer json
root to: "home#not_found"
# New Routes
get '/clk', to: 'home#click'
# wildcard for any route not matched
get "*unmatched_route", to: "tracking#not_found"
end
发现问题,它与 rails 5 中自动加载路径的更改有关。
现在 eager_load_paths 应该用在 application.rb 而不是 autoload_paths
参考资料:
https://github.com/rails/rails/commit/212ef5278b673aee304519d886d5db86a87b1437
https://blog.bigbinary.com/2016/08/29/rails-5-disables-autoloading-after-booting-the-app-in-production.html
我刚刚将我的 rails 项目从 rails 4.2 升级到 rails 5.1.4。升级后我的主控制器开始崩溃。当我调用它时,它会在路由文件上抛出一个错误,指出“未初始化的主控制器”
搜索了很长时间后,我在我的 heroku 服务器上将 config.cache_classes 设置为 false,突然一切正常。虽然我无法在我的本地环境中重现逻辑。
任何人都知道在哪里搜索修复程序或如何修复此问题?我已经搜索了好几天,但没有找到它可能是什么!
很高兴提供任何人认为有用的详细信息以提供帮助!问就是了!
Ruby 版本 2.4.2
** 编辑 - 根据要求添加信息 **
完整错误是:
ActionController::RoutingError (uninitialized constant HomeController):
2017-11-26T15:16:55.051341+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in `const_get'
2017-11-26T15:16:55.051342+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in `block in constantize'
2017-11-26T15:16:55.051343+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in `each'
2017-11-26T15:16:55.051343+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in `inject'
2017-11-26T15:16:55.051344+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in `constantize'
2017-11-26T15:16:55.051345+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:582:in `get'
2017-11-26T15:16:55.051346+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:613:in `constantize'
2017-11-26T15:16:55.051346+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/http/request.rb:85:in `controller_class_for'
2017-11-26T15:16:55.051347+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/http/request.rb:78:in `controller_class'
2017-11-26T15:16:55.051348+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:43:in `controller'
2017-11-26T15:16:55.051348+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:29:in `serve'
2017-11-26T15:16:55.051349+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:50:in `block in serve'
2017-11-26T15:16:55.051350+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `each'
2017-11-26T15:16:55.051350+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `serve'
2017-11-26T15:16:55.051351+00:00 app[web.1]: vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:834:in `call'
控制器基于/myapp/app/HomeController.rb
class HomeController < ActionController::API
def click
# Execution of method, removed to keep post small
end
end
/myapp/config 文件夹中的路由文件如下所示:
Rails.application.routes.draw do
# root is set to a explainer json
root to: "home#not_found"
# New Routes
get '/clk', to: 'home#click'
# wildcard for any route not matched
get "*unmatched_route", to: "tracking#not_found"
end
发现问题,它与 rails 5 中自动加载路径的更改有关。 现在 eager_load_paths 应该用在 application.rb 而不是 autoload_paths
参考资料: https://github.com/rails/rails/commit/212ef5278b673aee304519d886d5db86a87b1437 https://blog.bigbinary.com/2016/08/29/rails-5-disables-autoloading-after-booting-the-app-in-production.html