I have a Rails 2 project in which models are in sub-folders, but not in a name space
app/models/sub_folder/posts.rb
class Post < ActiveRecord::Base end
The controllers are also in sub-folders, but are name spaced (views also in a corresponding sub_folder).
app/controllers/sub_folder/posts_controller.rb
class SubFolder::PostsController < ApplicationController end
This works fine, but I want to move on to Rails 3, and it all falls apart...
In application.rb I have
config.autoload_paths += Dir["#{config.root}/app/models/**/"]
So Rails should be able to find the models. However running tests (which are subfoldered in an analogous way), I get
LoadError: Expected R:/test3/app/models/sub_folder/post.rb to define SubFolder::Post
So okay, suppose I name-space my models? Now I get:
LoadError: Expected R:/test3/app/models/sub_folder/post.rb to define Post
Taking the model out of it sub-folder does allow the tests to pass, but my real project has over 30 models, and I really do want them to be structured somehow.
Running on Rails version 3.2.2, with Ruby 1.9.2, on JRuby 1.6.7 by the way, and all the above are from a simple test project that I created just for this purpose; no custom code except as noted above. I have found several web pages about this issue, but they just indicate the config.autoload_paths bit should solve the problem; am I missing something simple here?