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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:23:03+00:00 2026-05-23T11:23:03+00:00

Consider this simple application in RUby on Rails: Student & Teacher extends Person. Person

  • 0

Consider this simple application in RUby on Rails:

Student & Teacher extends Person.
Person has 2 properties, name & age.
Student has 1 extra property, grade.
Teacher has 1 extra property, salary.

I want to store the student & teacher information in separate db tables. I want to take advantage of RoR’s utility class ActiveRecord:Base to retrive data for these models. Because Person is not expected to be instantiated, I can mix it with Student & Teacher as follows:

class Student < ActiveRecord:Base
include Person
end

module Person
end

Question:

  1. Is this the correct way of implementation?
  2. How to implement this without creating a databse table called persons? I only want to generate 2 tables, namely students and teachers, and both should have the 3 properties mentioned above.
  • 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-23T11:23:03+00:00Added an answer on May 23, 2026 at 11:23 am

    Person does not have to be a model – it can be a library/module (which you then mixin as per your example). You’d keep that in RAILS_ROOT/lib.
    Your Student and Teacher classes can be models (which use AR::Base), and the person can just be a bunch of common methods used by both.

    Alternatively, if your child class is far more complicated – look into “Single table inheritance” – the description of which is beyond the scope of this answer… but you can google for it.

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

Sidebar

Related Questions

I have a simple photo taking application that has the following design: [Consider the
Consider this simple XML document. The serialized XML shown here is the result of
Consider this simple markup: <body> <div style=border: 2px solid navy; position:absolute; width:100%; height:100%> </div>
Consider this simple example (which displays in red): echo -e \033[31mHello World\033[0m It displays
This may seem a very silly question. Consider this: I have a simple Boolean
I know this is a simple question, but I can't figure it out. Consider
Consider a simple table with an auto-increment column like this: CREATE TABLE foo (
I'm using the Kaminari gem for my ruby on rails application (For anybody still
Consider simple case where user is deleting a post. This is simple HTTP DELETE/POST
Let's consider this scenario: a freshly create windows form application in which I created

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.