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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:12:44+00:00 2026-05-13T15:12:44+00:00

Hey, all. Working on my first Rails app. I’ve searched all around – read

  • 0

Hey, all. Working on my first Rails app.

I’ve searched all around – read a bunch of tutorials, articles, and forum posts, watched some screencasts, and I’ve found a few examples that come close to what I’m trying to do (notably http://railscasts.com/episodes/154-polymorphic-association and ep 196 about nested model forms), but not exactly.

I have two models (Podcast and BlogPost) that need to be commentable, and I have a Comment model that is polymorphically related to both. The railscasts above had a very similar example (ep 154), but Ryan used a full set of nested routes, so there were specific templates for adding and editing comments. What I want to do is show the list of comments right on the Podcast or BlogPost page, along with an Add Comment form at the bottom. I don’t need a separate add template/route, and I don’t need the ability to edit, only delete.

This is a pretty common design on the web, but I can’t find a Rails example specifically about this pattern. Here’s my current understanding:

I need routes for the create and delete actions, of course, but there are no templates associated with those. I’m also guessing that the right approach is to create a partial that can be included at the bottom of both the Podcast and BlogPost show template. The logical name for the partial seems to me to be something like _comments.html.haml. I know it’s a common convention to have the object passed to the partial be named after the template, but calling the object ‘comments’ seems to not match my use case, since what I really need to pass is the commentable object (Podcast or BlogPost). So, I guess I’d use the locals option for the render partial call? (:commentable => @podcast).

Inside the partial, I could call commentable.comments to get the comments collection, render that with a second partial (this time with the conventional use case, calling the partial _comment.html.haml), then create a form that submits to… what? REST-wise, it should be a POST to the collection, which would be /podcast|blogpost/:id/comments, and I think the helper for that is podcast_comments_path(podcast) if it were a podcast – not sure what to do though, since I’m using polymorphic comments. That would trigger the Comment.create action, which would then need to redirect back to the podcast|blogpost path /podcast|blogpost/:id.

It’s all a bit overwhelming, which is why I was really hoping to find a screencast or example that specifically implements this design.

  • 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-13T15:12:44+00:00Added an answer on May 13, 2026 at 3:12 pm

    I figured it out, implemented it, tested it, then finally wrote a tutorial explaining how to do it for others:

    https://github.com/hcatlin/make_resourceful/wiki/embedded-nested-polymorphic-comments

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

Sidebar

Related Questions

Hey guys. I'm creating a rails app and being one of the first times
Hey all. We're sending quite a few emails (around 23k) using IIS6 SMTP service
Hey all - I have an app where I'm authenticating the user. They pass
Hey all. I've got a new app up and running on a new ubuntu
Hey all, i've been working on this small project in XNA the goal is
Hey guys, first off all sorry, i can't login using my yahoo provider. anyways
Hey all, have been working on designing a new database for work. They have
Hey all, I am not quite getting why this doesn't seem to be working.
Hey all Im working on a game for iphone using cocos2d and sdk 4.1
Hey all, working on a C++ little game, Connect 3. This is just like

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.