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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:28:29+00:00 2026-05-13T13:28:29+00:00

I have some issues in Rails Active Record Inheritance, I need to create a

  • 0

I have some issues in Rails Active Record Inheritance, I need to create a model that inherits parents class properties(fields) and should also hold its own properties.

Ex:
Parent Class

class Content < ActiveRecord::Base
end

Classes inheriting parent class (Content)

class Wiki < Content   // Inherting Class Content
end

class Video < Content   // Inherting Class Content
end

Suppose “content” table contains fields type,name (to store common fields)

  • “Wiki” table contains fields body,description
  • “Video” table contains fields filename,description

Inserting into content and wiki table as

def create
  WikiPage.new("name" =>"new_wikipage")
  @wiki_page = WikiPage.new(params[:wiki_page])
end

but, the problem is the newly created wikipage is not inserting(because the parent class “Content” is abstracting child class Wikipage param values)

Generating Error like method “body” not defined (field “body” is part of wiki table,which got hided by content table)

  • 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-13T13:28:29+00:00Added an answer on May 13, 2026 at 1:28 pm

    Rails uses single-table inheritance (STI) for model subclasses. This means that you don’t create a separate table for Wiki or Video in your database. They will all be stored in the “contents” table, and that table should include all the fields needed by all subclasses.

    It’s okay if not all subclasses use all the available fields. Rails then keeps track of what subclass a record is, using the “type” column of the parent table.

    I walk through this in detail in this article called Single-Table Inheritance with Tests in Rails. I think the code samples will give you a better idea of how to proceed.

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

Sidebar

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.