Rails automatically loads models from subfolders, but expects them to have a namespace.
/app/models/user.rb class User end /app/models/something/user.rb class Something::User end
If you incorrectly place your models in subfolders, this will ruin the Rails autoloader and cause the errors you see.
Remove this
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
And add the correct namespaces to your models and everything will work fine.
You can easily use models with names in your relationships, for example:
class User has_many :photos, class_name: 'Something::Photo' end user.photos (will be instances of Something::Photo)
If you do not want to use the namespace, but share your models for another reason, you can do this at the top level and use other folders next to the models. By default, rails load all folders in applications, so you can simply create the βmodels2β folder or whatever you want to name next to βmodelsβ. This will not affect the loading functionality of the rail class.
Based on your example, you can:
/app /controllers /models for all your normal models /housing for your "housing" models
Similarly, you can directly access them in the top-level namespace, with no class name parameters or anything else.
source share