Comments are not being nested

So for the convenience of all I have posted my code on gist. I am having
issues using the ancestry gem to nest comments. the issue is that said
comment does not nest under the parent comment, instead it is added to
the end of the comments list.

I have a relationship of tasks to comments, where a task has many
comments and a comment belongs to task. Your help is appreciated.

My code is posted here: Help with nesting comments · GitHub

On 13 September 2012 19:22, Kyle A. [email protected] wrote:

So for the convince of all I have posted my code on gist. I am having
issues using the ancestry gem to nest comments. the issue is that said
comment does not nest under the parent comment, instead it is added to
the end of the comments list.

I have a relationship of tasks to comments, where a task has many
comments and a comment belongs to task. Your help is appreciated.

My code is posted here: Help with nesting comments · GitHub

Have a look at the Rails Guide on Debugging. That will show you ways
of debugging your code. First home in on /exactly/ which section is
failing so that rather than saying “comment does not nest under the
parent comment, instead it is added to the end of the comments list”
you can point to a couple of lines of code and say what it is doing
wrong, so you can ask here again. In practice it is likely that
having homed in on the lines of code you will see yourself what the
problem is.

Colin

Colin L. wrote in post #1075895:

On 13 September 2012 19:22, Kyle A. [email protected] wrote:

So for the convince of all I have posted my code on gist. I am having
issues using the ancestry gem to nest comments. the issue is that said
comment does not nest under the parent comment, instead it is added to
the end of the comments list.

I have a relationship of tasks to comments, where a task has many
comments and a comment belongs to task. Your help is appreciated.

My code is posted here: Help with nesting comments · GitHub

Have a look at the Rails Guide on Debugging. That will show you ways
of debugging your code. First home in on /exactly/ which section is
failing so that rather than saying “comment does not nest under the
parent comment, instead it is added to the end of the comments list”
you can point to a couple of lines of code and say what it is doing
wrong, so you can ask here again. In practice it is likely that
having homed in on the lines of code you will see yourself what the
problem is.

Colin

taking this into consideration and spending what seems like for ever
scouring the internet and reading articles, even going over the tutorial
I go thris from I have come to the conclusion that it is a few things.

One:

module CommentsHelper
def nested_comments(comments)
comments.map do |comment, sub_comments|
render(comment) + content_tag(:div, nested_comments(sub_comments),
:class => ‘nested_comments’)
end.join.html_safe
end
end

the code should display something like this when I rendered out
comments,
before it could do comments.map

{ #<TreeNode id: 100018, name: “Stinky”, ancestry: nil>
=> { #<TreeNode id: 100019, name: “Crunchy”, ancestry: “100018”>
=> { #<TreeNode id: 100020, name: “Squeeky”, ancestry:
“100018/100019”>
=> {}
}
}
}

except it doesn’t, I get

{ #<TreeNode id: 100018, name: “Stinky”, ancestry: nil>}
{ #<TreeNode id: 100019, name: “Crunchy”, ancestry: nil>}
{ #<TreeNode id: 100020, name: “Squeeky”, ancestry: nil>}
{}

So there’s something wrong with the helper even when its the same as the
example tutorial I was following

Two:

parent_id is apparently an attribute of comments, how ever in the
example I followed they did not have to assign it as a accessible
attribute, where as I do - else I get an error - plus there is no column
for parent_id - as there ins’t suppose to be one, just ancestry and an
index of ancestry - which I have tripple checked

How ever with all that said the code seems to work. so I kept moving on

  • One of the other issues after playing with the code is the helper
    method.

if I take this:

module CommentsHelper
def nested_comments(comments)
comments.map do |comment, sub_comments|
render(comment) + content_tag(:div, nested_comments(sub_comments),
:class => ‘nested_comments’)
end.join.html_safe
end
end

and replace the nested_comments(sub_comments) with ‘hello’ I get

[commnet]
hello
[comment]
hello

So with that new information. what else should I be looking for? I have
red all the documentation I can, poured over examples, read he out put a
thousand times. I have printed out comments, I have tried different
styles such as @tasks.comments - as comments belong to tasks. and still
I am lost.

On 13 September 2012 21:28, Kyle A. [email protected] wrote:

My code is posted here: Help with nesting comments · GitHub
Colin
render(comment) + content_tag(:div, nested_comments(sub_comments),
{ #<TreeNode id: 100018, name: “Stinky”, ancestry: nil>
{ #<TreeNode id: 100018, name: “Stinky”, ancestry: nil>}
parent_id is apparently an attribute of comments, how ever in the

and replace the nested_comments(sub_comments) with ‘hello’ I get
I am lost.
OK, I misunderstood what you had already done. I think you are saying
it is a problem with the ancestry gem itself. Sorry I have not used
that. Anyone else?

Have you tried using the gem in the simplest way possible to make sure
you understand how it is supposed to work?

Which version of Rails are you using?

Colin

On 13 September 2012 21:51, Kyle A. [email protected] wrote:

I am lost.

Yes. I am 100% sure I understand the full usage of the gem and have
tripple checked documentation, stack over flow and other blogs, its not
an issue with the gem, its an issue with my code.

it boils down to two things:

position_id spazzes out if it is not an accessible attribute, which in
the documentation plus the examples I have read and followed - does not
need to be.

That could be an issue with the version of Rails you are using, I
asked which one it is.

ancestry seems to always be nil and because of this comments are not
nesting properly. so I am wondering how to make sure it gets set -
according to the documentation it should just be set when ever you reply
to a comment, because it uses the parent comments id to do so.

So I am wondering whats wrong with my code for this to not work >.<

Which line of your code is not doing the correct thing?

Colin

Colin L. wrote in post #1075908:

On 13 September 2012 21:51, Kyle A. [email protected] wrote:

I am lost.

Yes. I am 100% sure I understand the full usage of the gem and have
tripple checked documentation, stack over flow and other blogs, its not
an issue with the gem, its an issue with my code.

it boils down to two things:

position_id spazzes out if it is not an accessible attribute, which in
the documentation plus the examples I have read and followed - does not
need to be.

That could be an issue with the version of Rails you are using, I
asked which one it is.

ancestry seems to always be nil and because of this comments are not
nesting properly. so I am wondering how to make sure it gets set -
according to the documentation it should just be set when ever you reply
to a comment, because it uses the parent comments id to do so.

So I am wondering whats wrong with my code for this to not work >.<

Which line of your code is not doing the correct thing?

Colin

Sorry Colin, if it was a one line issue I wouldn’t bother with mailing
lists, I would double check the code. this is “what’s wrong with my
code” issue, hence why I posted gist. and ancestry works with 3.2 I know
that much, but thanks for your help

any one else?

Colin L. wrote in post #1075904:

On 13 September 2012 21:28, Kyle A. [email protected] wrote:

My code is posted here: Help with nesting comments · GitHub
Colin
render(comment) + content_tag(:div, nested_comments(sub_comments),
{ #<TreeNode id: 100018, name: “Stinky”, ancestry: nil>
{ #<TreeNode id: 100018, name: “Stinky”, ancestry: nil>}
parent_id is apparently an attribute of comments, how ever in the

and replace the nested_comments(sub_comments) with ‘hello’ I get
I am lost.
OK, I misunderstood what you had already done. I think you are saying
it is a problem with the ancestry gem itself. Sorry I have not used
that. Anyone else?

Have you tried using the gem in the simplest way possible to make sure
you understand how it is supposed to work?

Which version of Rails are you using?

Colin

Yes. I am 100% sure I understand the full usage of the gem and have
tripple checked documentation, stack over flow and other blogs, its not
an issue with the gem, its an issue with my code.

it boils down to two things:

position_id spazzes out if it is not an accessible attribute, which in
the documentation plus the examples I have read and followed - does not
need to be.

ancestry seems to always be nil and because of this comments are not
nesting properly. so I am wondering how to make sure it gets set -
according to the documentation it should just be set when ever you reply
to a comment, because it uses the parent comments id to do so.

So I am wondering whats wrong with my code for this to not work >.<

On 13 September 2012 22:48, Kyle A. [email protected] wrote:

position_id spazzes out if it is not an accessible attribute, which in
to a comment, because it uses the parent comments id to do so.
code" issue, hence why I posted gist. and ancestry works with 3.2 I know
that much, but thanks for your help

It may not be a single line problem but it is certainly not necessary
to look at the whole code. The first principle of debugging is to
narrow down the problem. Have you determined whether the correct data
are getting stored in the database? If not then concentrate on that
first. If the problem is that the data are not getting stored
properly then that narrows it down to the sections of code that get
the data into the database, if the correct data are getting stored
then the problem is a problem with viewing the data. Either way you
have halved the extent of the code you need to look at.

To track down the problem with parent_id then remove it from
attr_accessible and post the full failure message and the bit of
development.log that corresponds to the action that generates the
error.

Colin

Colin

So I have updated the gist Help with nesting comments · GitHub to show more
information