elight / acts_as_commentable_with_threading

Similar to acts_as_commentable; however, utilizes awesome_nested_set to provide threaded comments
MIT License
672 stars 167 forks source link

How I know which level a comment is on? #89

Closed nadeemja closed 9 years ago

nadeemja commented 9 years ago

Hi,

I'm trying indent comments based on how nested they are. How can I know?

I'm calling Model.comment_threads.

Regards,

Nadeem J. Qureshi

rescribet commented 9 years ago

I currently use a local variable in my views, which boils down to this:

- @comments.each do |c|
      = render partial: 'comments/comment', locals: { c: c, depth: 1 }

And in comment/_comment.html.slim

p[class="comment comment-#{depth}"]= c.body
- c.children.each do |ch|
      = render partial: 'comments/comment', locals: { c: ch, depth: depth+1 }

After which you can style the indentation based on .comment-n, alternatively you could give each .comment a left margin except for the root comments.

nadeemja commented 9 years ago

Hi @fletcher91

Thanks for your reply. I too tried that. But, since AACWT is based on ANS, you can add field depth to your model and everything works automagically :)

rescribet commented 9 years ago

Hi @nadeemja

That's really nice actually, thanks for the tip!

~tvk