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 8964211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:32:10+00:00 2026-06-15T16:32:10+00:00

I’m creating a message-board website using Rails. I have a Topic class and Post

  • 0

I’m creating a message-board website using Rails. I have a Topic class and Post class.
it is easy to notice the similarity between the two classes (content, title, user_id..)

what is the best practice in Rails with this scenario?
should Topic inherit from Post? how does it work?

  • 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-06-15T16:32:11+00:00Added an answer on June 15, 2026 at 4:32 pm

    Module Mixins: just include this module on any class

    Inheritance (STI): you have to use the same table for those classes

    Polymorphic: you have to use a different tables for each class

    In my opinion, its really hard to answer in general what is the best practice, since it really depends on the situation–in some cases you may even want to use a combination, god forbid.

    I would stick with Module Mixins because its simple and flexible. If you think you’ll be double writing queries a lot because you have two separate tables, then try Inheritance (STI). From experience, definitely Polymorphic can be a headache, with a ton of gotchas if your not familiar, so probably not worth it for 2 classes.

    # Heres one way to set up Inheritance (STI) on a table called 'contents'
    class Content < ActiveRecord::Base
        attr_accessible :content, :title
        belongs_to :user
    end
    
    class Topic < Content
    end
    
    class Post < Content
    end
    
    Content.all             # => query topics and posts
    #Post.all + Topic.all   # => query topics and posts without STI (doublewriting query)
    
    Post.all    # => only query posts
    Topic.all   # => only  topics
    

    General Rails best practice? K eep I t S imple S tupid

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I used javascript for loading a picture on my website depending on which small

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.