Rails 3.2.9和子文件夹中的模型 [英] Rails 3.2.9 and models in subfolders
本文介绍了Rails 3.2.9和子文件夹中的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于rails 3.2.9,我无法将模型存储在子文件夹中.在我的应用中,我有这棵树:
Since rails 3.2.9 I'm unable to store models in subfolders. In my app I have this tree:
models
-type_models
-assets
-user
-concerns
在application.rb中也有
Also in application.rb there is
config.autoload_paths += Dir["#{config.root}/app/models/*"]
一切正常,直到Rails 3.2.9.现在,我有未知常量"错误. 我不想为大量模型命名空间并修复所有应用程序以使用命名空间模型.
All things was ok till rails 3.2.9. Now I have "Unknown constant" error. I don't want to namespace tons of model and fix all app to use namespaced models.
Warning: Error loading /var/www/my_app/app/models/type_models/context_type.rb:
uninitialized constant TypeModels::ContextType
文件context_type.rb:
file context_type.rb:
class ContextType ... end
推荐答案
在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,一切都准备就绪!
Restart Rails and you're all set!
这篇关于Rails 3.2.9和子文件夹中的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文