I have an application for card games that uses single page inheritance. I have class Cardand a database table cardswith a column typeand several subclasses Card(including class Foo < Cardand class Bar < Cardfor the argument).
As it happens, Foothis is a card from the original print of the game, and Barthis is a card from the extension. In an attempt to streamline my models, I created a directory structure as follows:
app/
+ models/
+ card.rb
+ base_game/
+ foo.rb
+ expansion/
+ bar.rb
And the modified .rb environment contains:
Rails::Initializer.run do |config|
config.load_paths += Dir["#{RAILS_ROOT}/app/models/**"]
end
However, when my application reads a map from the database, Rails throws the following exception:
ActiveRecord::SubclassNotFound (The single-table inheritance mechanism failed to locate the subclass: 'Foo'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Card.inheritance_column to use another column for that information.)
Can this work be done, or am I doomed to a flat directory structure?