ruby - 无法自动加载常量 Controller (在生产中)。开发没有错误

标签 ruby ruby-on-rails-4 amazon-web-services

文件名-

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/

相关文章:

amazon-web-services - 如何从 AWS EMR 下载 Zeppelin Notebook

amazon-web-services - AWS 时间流 : Unable to ingest records into AWS Timestream

ios - AWS dynamodb 查询大多数时候崩溃

ruby-on-rails - 使用 Rails Composer 工具创建 rails 应用程序时显示 "/Gemfile not found"错误

ruby-on-rails - rbenv 路径错误的 Rails Capistrano?

ruby-on-rails - Ruby 动态正则表达式条件

ruby-on-rails - 服务器启动时如何修复 "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5"

ruby-on-rails - 在 Rails 4.2 和 Ruby 2.2.0 中接收二进制文件时出错

ruby - Minitest 不会通过,尽管使用 binding.pry 检查时标准是正确的

javascript - 变量计算完成后如何将变量从 Controller 传递给javascript?