Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 810605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:54:46+00:00 2026-05-15T00:54:46+00:00

I have a card-game application which makes use of Single Table Inheritance. I have

  • 0

I have a card-game application which makes use of Single Table Inheritance. I have a class Card, and a database table cards with column type, and a number of subclasses of Card (including class Foo < Card and class Bar < Card, for the sake of argument).

As it happens, Foo is a card from the original printing of the game, while Bar is a card from an expansion. In an attempt to rationalise my models, I have created a directory structure like so:

app/
+ models/
  + card.rb
  + base_game/
    + foo.rb
  + expansion/
    + bar.rb

And modified environment.rb to contain:

Rails::Initializer.run do |config|
  config.load_paths += Dir["#{RAILS_ROOT}/app/models/**"]
end

However, when my app reads a card 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.)

Is it possible to make this work, or am I doomed to a flat directory structure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:54:46+00:00Added an answer on May 15, 2026 at 12:54 am

    Probably the best way to do this would be to nest the Foo class inside a BaseGame module.

    A ruby module is roughly similar to a package structure in other languages, it’s a mechanism for partitioning related bits of code into logical groups. It has other functions such as mixins (which you can find explained here: http://www.rubyfleebie.com/an-introduction-to-modules-part-1/) but in this instance they’re not relevant.

    You’ll need to reference and instantiate the class slightly differently. For example you’d query it like this:

    BaseGame::Foo.find(:all,:conditons => :here)
    

    Or create an instance of it like this:

    BaseGame::Foo.new(:height => 1)
    

    Rails supports modularized code for Active Record models. You just need to make a few changes to where the class is stored. say for example you move the class Foo into a module BaseGame (as in your example), you need to move apps/models/foo.rb to apps/models/base_game/foo.rb.So you’re file tree will look like:

    app/
     + models/
      + card.rb #The superclass
       + base_game/
          + foo.rb
    

    To declare this on the class define like so:

    module BaseGame
      class Foo < Card
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a card game in ruby. I have the Game class, which
I have a small card game for Google+ which needs the visitor's name, avatar,
So, i'm attempting simple card game. I have player class with draw function, and
I have a small card game at Facebook (and few Russian social networks), which
I have a Rails 2.3.5 app which is serving a card game. I've been
I have a simple card game (using 52 cards - no jokers) that I
I have been looking into different database libraries for my online card game (PostgreSQL,
In Clojure I am building a card game. Cards have a suit and a
So I am writing a class that plays the card game war. I have
I have a card game (screenshot below) in which I display player avatars. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.