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

  • Home
  • SEARCH
  • 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 6116773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:14:41+00:00 2026-05-23T15:14:41+00:00

I’m making a forum in Rails with the traditional Topic has many Posts setup.

  • 0

I’m making a forum in Rails with the traditional Topic has many Posts setup.

However, the forum revolves around a forum game played by users that are pretty much just glorified Topics where the users play by taking turns posting.

In an effort to prototype my application, I created these models:

Topic has many Posts
Game has many GamePosts
InterestCheck has many InterestCheckPost

How it works:

  • Users create an InterestCheck in the Find A Game subforum.
  • When they find interested players, they start a Game in the Games subforum.
  • And general discussion, news bulletins, and other convention message board use are made into Topics.

The reason I created new models for Games and InterestChecks is because I want to add specific metadata to them. For instance, Games can be tagged with various tags while Topics can’t.

But it’s obviously really ugly and repetitive because I’m recreating the same Topic has many Posts scenario for Games and InterestChecks. And it creates some really ugly routes like new_game_game_post_path.

Question

I’ve been stuck on how to implement this for a while, now. Topics, Games, and InterestChecks all have the same Topic/Post functionality, but I want to ensure that I can extend and add metadata on Games and InterestChecks which is why STI doesn’t seem like the solution unless I’m mistakne.

  • 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-23T15:14:42+00:00Added an answer on May 23, 2026 at 3:14 pm

    You should be able to do this with single table inheritance and polymorphic associations.

    Single table inheritance, which Rails natively supports, will let you have just one Topics table from which Games and InterestChecks can inherit.

    Your Topic models will look like:

    class Topic < ActiveRecord::Base
      ...
    end
    
    class Game < Topic
      ...
    end
    
    class InterestCheck < Topic
      ...
    end
    

    Just add a type column to the Topic table. For example, Game.all is really just Topic.where(:type => 'game').

    Polymorphic associations will let all of your Topic models access the same Post table.

    Your Post model will look like:

    class Post < ActiveRecord::Base
      belongs_to :postable, :polymorphic => true
      ...
    end
    

    And you support this in your Topic model with:

    class Topic < ActiveRecord::Base
      has_many :posts, :as => :postable
    end
    

    And you’ll need to add the postable_type:string and postable_id:integer to your Post table. Or you can accomplish the same with just t.references :postable, :polymorphic => true in your Post migration and it’ll add the columns for you.

    I haven’t tested this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.