I have my models and controllers set up in sub-folders, so, for example, sample.rb is in app/models/sample_log, and samples_controller.rb is in app/controllers/sample_log. The controllers are defined to be within a namespace just though the class name, eg like this:
class SampleLog::SamplesController < SampleLog::SuperController
However, the models are not.
class Sample < ActiveRecord::Base
Instead, I have added the relevant directories to config.load_paths in environment.rb. Unit testing, functional testing and integration testing all pass without a problem, and I can use the Rails console normally too.
However, trying to access the web pages leads to some problems...
Putting a print statement in sample.rb, I can see that it is only when I try to access a page with a sample on it that sample.rb gets loaded, which makes perfect sense. However, it then throws an error:
Expected R:/samplelog/app/models/sample_log/sample.rb to define SampleLog::Sample
This seems to be thrown after the file has been completely loaded, I am guessing another model is loaded (as the page also uses a subclass of Sample), and this references the Sample class, and Rails objects because it cannot find the class.
Even though it has just loaded it...
I have experimented with forcing a load or require for each file without success. Using load generates a "superclass mismatch for class BatchSample" (BatchSample being the subclass of Sample). Using require leads to the original problem, albeit on reloading the page or going to another page in the section (the first show is good, however). Curiously, even when using require, Rails still loads the file twice for each page view. It seems not to realise the file is already loaded.
I have also tried adding the path to eager_load_paths, in the hope that the models would get loaded at boot up, but that made no difference (and the files were not loaded any earlier).
I wonder if anyone can shed any light, or give any suggestions.
I appreciate using a SampleLog namespace is one option, however, experiments in that direction turned up other problems.
Using Rails 2.2.2 with JRuby 1.5 by the way.