Config.cache_classes在heroku上统一了常量控制器

时间:2017-11-26 09:22:44

标签: ruby heroku ruby-on-rails-5.1

我刚刚将rails项目从rails 4.2升级到rails 5.1.4。升级后,我的主控制器开始崩溃。当我调用它时,它会在routes文件上抛出一个错误,指出“未初始化的主控制器”

搜索了很长时间后,我在我的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文件夹中的routes文件如下所示:

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

1 个答案:

答案 0 :(得分:0)

发现问题,这与自动加载路径的rails 5的更改有关。 现在应该在application.rb中使用eager_load_paths而不是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