Rails 3.2.9和子文件夹中的模型
由于rails 3.2.9我无法在子文件夹中存储模型。 在我的应用程序中,我有这棵树:
models -type_models -assets -user -concerns
同样在application.rb中
config.autoload_paths += Dir["#{config.root}/app/models/*"]
所有事情都没问题,直到3.2.9。 现在我有“未知常量”错误。 我不想命名大量模型并修复所有应用程序以使用命名空间模型。
Warning: Error loading /var/www/my_app/app/models/type_models/context_type.rb: uninitialized constant TypeModels::ContextType
file context_type.rb:
class ContextType ... end
尝试使用:
config.autoload_paths += Dir["#{config.root}/app/models/**/"]
在config/application.rb
:
config.autoload_paths += %W(type_models assets user concerns).map { |folder| "#{config.root}/app/models/#{folder}"}
在models/type_models/context_type.rb
:
class TypeModels::ContextType < ActiveRecord::Base ... end
重新启动Rails,你们都已经完成了!
包装你的class ContextType ... end
模块:
module TypeModels class ContextType # blah blah end end