I implemented STI in one of my models, using some tips from Alex Reisner's blog post. I already had all my subclasses use the superclass's controller, with serialize/store to hold the extra attributes. I added the model_name
and self.select_options
methods to the superclass, and the preload initializer from Alex's blog. I also changed my collection_select
in the _form view helper and attribute validation to use the self.select_options
method. All my subclasses are in individual files in a app/models/subfolder, though they're not namespaced like SubFolder::Subclass.
Then I start running into problems. Upon changing any code, self.select_options
stops returning all of the subclasses. It only returns a small subset or none. Thus due to the validation and _form tie-in, I can't edit/update my models after a code change. From what I could tell, when I change any code, Rails reloads the environment, but not the models in the subfolder.
I tried adding the routes to config.autoload_paths like many suggest, but ultimately that didn't work.
So ultimately, I want:
- Something to fix the autoloading, so I won't have to restart the server after every change
- Base it off the subdirectory containing all the children, to avoid manually maintaining an array
- Rails 3.2.11, ruby 1.9.3p125, ubuntu 12.04.01, rvm