文件名-
app/controllers/invoice/inventory/department/pharmacy_invoices_controller.rb
文件内容-
class Invoice::Inventory::Department::PharmacyInvoicesController < ApplicationController
...
end
我在开发中没有遇到错误,但在生产中我遇到了这个错误 -
F, [2016-04-25T13:08:00.754597 #13500] FATAL -- :
LoadError (Unable to autoload constant Invoice::Inventory::Department::PharmacyInvoicesController, expected /xxxxxx/yyyyyyy/app/controllers/invoice/inventory/department/pharmacy_invoices_controller.rb to define it):
我做了 ssh 并检查了服务器上的每个文件。它与开发相同,这是显而易见的。我不明白为什么它会在生产中抛出这样的错误。
最佳答案
这在 Rails 文档中有介绍,特别是在 Autoloading and Reloading Constants 中和 Nesting .
这是因为定义嵌套可以通过两种方式完成,并且在 Rails 中的理解方式有很大不同。您可以使用 Module.nesting
进行检查:
module Foo
class Bar
Module.nesting
end
end
=> [Foo::Bar, Foo]
class Foo::Bar
Module.nesting
end
=> [Foo::Bar]
如果您想了解更多,我推荐 Simon Coffey 这篇非常好的博客文章:Rails Autoloading Hell
关于ruby - 无法自动加载常量 Controller (在生产中)。开发没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36834930/