The following problem has been fixed, I added an 's' to the end of comments, when it should just be comment, but a new problem has arisen at the bottom of this post.
I am trying to get threaded comments for my already existing comments system by following the answer to this man's question: Reddit-style nested/threaded/indented comments for Rails? When I try to access my article show page, I get the following error: undefined method `children' for # Here's the view from my article show page that is problematic:
<div id="comment <%= comment.id %>">
<%= comment.title %>
| <%= link_to "Edit Comment", edit_article_comment_path(@commentable, comment) %>
| <%= link_to 'Delete Comment', [@commentable, comment], :confirm => "Are you sure?", :method => :delete %><br />
<%= comment.content %><br />
**<%= render :partial => 'comments/comment', :collection => @comments.children %>**
<%= comment.user.name %><br /><br />
</div>
It's the render portion that is having a problem. If I take out the children part from the comments, I get this in my console: The recursion never stops. I get this: Rendered comments/_form.html.erb (14.9ms) Rendered comments/_comment.html.erb (2.0ms) Rendered comments/_comment.html.erb (7.3ms) Rendered comments/_comment.html.erb (12.3ms) Rendered comments/_comment.html.erb (17.9ms) Rendered comments/_comment.html.erb (22.3ms) Rendered comments/_comment.html.erb (26.8ms) Rendered comments/_comment.html.erb (31.6ms) Rendered comments/_comment.html.erb (36.2ms) .... I do not know why it keeps rendering. None of the comments have children, so it should stop. Here's the 'show' part of the article controller:
def show @article = Article.find(params[:id]) @commentable = Article.find(params[:id]) @comments = @commentable.comments.paginate(:page => params[:page]) @comment = Comment.new @title = @article.title end
My only explanation is that maybe there aren't any children comments, so will_paginate does not know what to do with it, so it throws an error at me.
New Problem, I am having problem with routing for comments. I am using polymorphic associations for my comments so they can be used for different models(articles, profiles, pictures, etc.), but I do not know how to create the routing paths in my view. Here is what I have now:
<div id="comment <%= comment.id %>">
<%= comment.title %>
| <%= link_to "Permalink", article_comment_path(@commentable, comment) %>
| <%= link_to "Reply", new_article_comment_path(@commentable, @comment_child) %>
| <%= link_to "Edit Comment", edit_article_comment_path(@commentable, comment) %>
| <%= link_to 'Delete Comment', [@commentable, comment], :confirm => "Are you sure?", :method => :delete %><br />
<%= comment.content %><br />
<%= comment.user.name %><br /><br />
<%= render :partial => 'comments/comment', :collection => @comment.children %>
</div>
There is an abundant number of pathing errors that won't work for other models. I am using: article_comment_path, new_article_comment_path, and edit_article_comment_path. By the way, this is inside of a for each loop, which loops over an array of comments. I want something like "commentable_comment_path" or "new_commentable_comment_path", so I can use it for my other models.
One more quick question, will this fix my "reply" link? I am not sure if I am doing that right. I want the reply link to create a comment within a comment.
Thank you so much.