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

  • Home
  • SEARCH
  • 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 3304716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:05:30+00:00 2026-05-17T21:05:30+00:00

I am following Ryan Bate’s tutorial: http://railscasts.com/episodes/163-self-referential-association But my setup is slightly different. I

  • 0

I am following Ryan Bate’s tutorial: http://railscasts.com/episodes/163-self-referential-association

But my setup is slightly different.

I am making comments that are self-referential so that comments can be commented on.

The form displays in the view, but when I submit, I get this :

Routing Error

No route matches "/conversations"

And my url says this : http://localhost:3000/conversations?convo_id=1

models

#conversation.rb
belongs_to :comment
belongs_to :convo, :class_name => "Comment"

#comment.rb
belongs_to  :post
has_many :conversations
has_many :convos, :through => :conversations

My form :

- for comment in @comments
  .grid_7.post.alpha.omega
    = comment.text
    %br/
    - form_for comment, :url => conversations_path(:convo_id => comment), :method => :post do |f|
      = f.label 'Comment'
      %br/
      = f.text_area :text
      %br/
      = f.submit 'Submit'

My conversations_controller:

def create
  @conversation = comment.conversations.build(:convo_id => params[:convo_id])

The app fails here in its creation as it never makes it to the redirect portion of the create method.

  • 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-17T21:05:30+00:00Added an answer on May 17, 2026 at 9:05 pm

    There are several pieces to work on here, but the good news is I think the answer you’re looking for is simpler than what you already have. If I understand you correctly, you want comments to have many child comments of their own. This is how YouTube works, letting members reply to existing comments. For this, you don’t need the has_many :through solution you’ve implemented. You don’t need the conversations object at all. A comment may have many replies (child comments), but a reply isn’t going to have more than one parent.

    The answer for this is using polymorphism, which is easier to implement than it is to pronounce 🙂 You want your comments to either belong to a post, or to another comment. Polymorphism lets an object belong to one of possibly many things. In fact, comments are the most common use for this.

    I cover polymorphism with the example of addresses in this blog post:

    http://kconrails.com/2010/10/19/common-addresses-using-polymorphism-and-nested-attributes-in-rails/

    But I can show you how it applies to your case more specifically. First, drop the conversation model/controller/routes entirely. Then, change your comments table:

    change_table :comments do |t|
      t.integer :commentable_id
      t.string  :commentable_type
    
      t.remove :post_id
    end
    

    We don’t need post_id anymore, because we’re going to change how we associate with other tables. Now let’s change the models:

    # app/models/post.rb
    has_many :comments, :as => :commentable
    
    # app/models/comment.rb
    belongs_to :commentable, :polymorphic => true
    has_many :comments, :as => :commentable
    

    Notice we dropped the comment belonging to a post directly. Instead it connects to the polymorphic “commentable” association. Now you have an unlimited depth to comments having comments.

    Now in your Post#show action, you’ll want to create a blank comment like so:

    get show
      @post = Post.find(params[:id])
      @comment = @post.comments.build
    end
    

    @comment will now have commentable_id and commentable_type set for you, automatically. Now in your show page, using erb:

    <% form_for @comment do |f| %>
      <%= f.hidden_field :commentable_type %>
      <%= f.hidden_field :commentable_id %>
    
      /* other fields go here */
    <% end %>
    

    Now when Comments#create is called, it works like you’d expect, and attaches to the right parent. The example above was showing a comment being added directly to a post, but the process is essentially the same for a comment. In the controller you’d call @comment.comments.build, and the form itself would stay the same.

    I hope this helps!

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

Sidebar

Related Questions

I've been following Ryan Bates Railscast on Subdomains http://railscasts.com/episodes/221-subdomains-in-rails-3 and using lvh.me to serve
I am following Ryan Bates's tutorial on Rails 3 ActionMailer . I generate the
I following Ryan's subdomain railscast where het creates a Subdomain class used in his
Following http://maksim.sorokin.dk/it/2010/06/10/izpack-with-maven/ I wrote a Maven POM which creates an IzPack installer, using the
Following on from my recent question on Large, Complex Objects as a Web Service
Following my question regarding a .NET YAML Library ... as there doesn't seem to
Following this question: Good crash reporting library in c# Is there any library like
Following Izb's question about Best binary XML format for JavaME , I'm looking for
Following on from this question what would be the best way to write a
Following techniques from 'Modern C++ Design', I am implementing a persistence library with various

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.