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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:49:53+00:00 2026-05-25T09:49:53+00:00

I am using Rails single-table inheritance with a superclass Content and a number of

  • 0

I am using Rails single-table inheritance with a superclass Content and a number of subclasses (such as Article, Comment etc.) I am trying to get away with a single controller, and I have set up the routes thusly:

resources :contents
resources :articles, :controller => "contents"
resources :comments, :controller => "contents"

This way, /articles/new gets routed to contents#new which seems to be what I want.

Within the controller and the views, however, I need to tailor the functionality a bit depending on which actual model I am dealing with. For that purpose, I need to determine the original requested resource or otherwise find out which subclass I am dealing with.

Looking at params for /articles/newwithin the common controller gives {"action"=>"new", "controller"=>"contents"}, which obviously does not provide the information I need.

Either the answer is really obvious or I am using model inheritance wrong. Which one is it? 🙂

  • 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-25T09:49:54+00:00Added an answer on May 25, 2026 at 9:49 am

    You can extract the part of the request path you are interested in like this

    path = request.fullpath[%r{^/(articles|comments)/}, 1] # articles or comments
    

    Once you have it you can get the model class like that:

    model_class = path.classify.constantize # Article or Comment
    

    Bests,

    Richard

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

Sidebar

Related Questions

I am using single table inheritance in my rails application, and want to explicitly
I am using Single-Table Inheritance (STI) on one of my models for a Rails
I am using single table inheritance in ROR3 so I created these models: class
Single Table Inheritance using ActiveRecord. Since we can use @test = Employee.all and find
I would like a little confirmation that I'm doing this correctly. Using rails single
I'm trying to get the not confirmed warning to go away when using Yahoo!
I am using rails 3 with backbone.js 0.53 and currently receive a GET with
Using Rails v2.1, lets say you have an action for a controller that is
When using Rails date_select with :prompt => true I see some very strange behavior
I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js .

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.