我试图使用一个缩写(全部大写)的命名空间,但似乎无法搞清楚。我总是收到“无法自动加载”错误消息。
这是一个例子:
routes.rb中:
namespace 'ASAP' do
resources :foos
end
尽快/ foos_controller.rb:
class ASAP::FoosController < ApplicationController
def index
head :ok
end
end
配置/是inflections.rb:
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym 'ASAP'
end
错误信息:
Unable to autoload constant Asap::FoosController, expected app/controllers/asap/foos_controller.rb to define it
任何帮助表示赞赏!
代码中的所有内容看起来都很好,只是inflections.rb
文件需要通过放入config/initializers
而不是/config
路径来加载。
来自Rails:
# Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded.
而不是在这里:
config
└── inflections.rb
这里:
config
└── initializers
└── inflections.rb