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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:30:08+00:00 2026-05-18T07:30:08+00:00

I am new to using inherited resources and want to use it for polymorphic

  • 0

I am new to using inherited resources and want to use it for
polymorphic nested comments. I have several objects that will be
commentable (articles, galleries, etc.) and comments can also be
nested. I’m using a combination of awesome_nested_set (parent_id,
lft, rgt) with my Comment model having polymorphic commentable
columns.

The controller needs to receive an AJAX request (only) for the create
action and perform as below:

Posting to /articles/12/comments/34 creates a comment with commentable equal to @article (12) and parent equal to @comment (34)

/articles/12/comments/34

Posting to /gallery/12/comments/34 creates a comment with commentable equal to
@gallery (12) and parent equal to @comment (34)

I’m a bit stuck on where to begin. Is this a good use case for
inherited resources?


class CommentsController < InheritedResources::Base 
  respond_to :js, :only => :create 
  belongs_to :article, :cheat, :gallery, :video, :polymorphic => true 
do 
    belongs_to :comments 
  end 
  def create 
    create! do |format| 
       # How in here do I build a comment so that it handles 
polymorphism? 
       @comment.children.create(:commentable => @article or @cheat or 
@something_generic?) 
    end 
  end 
end 
  • 1 1 Answer
  • 2 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-18T07:30:09+00:00Added an answer on May 18, 2026 at 7:30 am

    Nested comments are difficult. Rails resources don’t provide in passing an id to the create action, so I don’t think you can properly POST to the create action this way. You might need to add comment to the belong_to options, so you can post to /comments/33/comments. I don’t know if InheritedResources support this. If it does, object creation should be automatic. You can reference stuff like parent_url too.

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

Sidebar

Related Questions

I'm new to Entity Framework and am using Database First. I have inherited a
I'm new to sencha touch. I have a list-search example. Now I want to
I have a timer in my class that is I only ever want one
I am new to Spring and inherited a Spring project that had all the
I'm using Inherited Resources for my Rails 2.3 web service app. It's a great
The code I have inherited is using the three Entity Framework installers from here:
I'm new to C++ and inherited the following code that is supposed to transform
I've inherited a website developed using Struts 1.2 that I need to make some
I'm relatively new to NHibernate, but have been using it for the last few
I inherited a project that uses MvcMiniProfiler and now I have to go in

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.