elight / acts_as_commentable_with_threading

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

Illustrative tutorial on implementing the gem #83

Closed damienh closed 8 years ago

damienh commented 10 years ago

Hi,

I have had a look around and cannot find a decent tutorial showing you how you can go about implementing this gem for a fully commendable model with threaded replies. If anyone knows of one I would be in your debt.

Damien

damienh commented 10 years ago

anyone?

Moutix commented 10 years ago

Hi,

I do not know if it's the best way to do this, but here's how I did it

I made a helper to check the deepness of each comment

app/helper/comments_helper.rb

module CommentsHelper

  def stack_helper comments
    i = 0
    stack = comments.to_a
    while comment = stack.pop
      if comment == :end
        i-=1
        next
      end

      yield comment, i
      i+=1
      stack.push(:end)
      stack.concat(comment.children)
    end
  end

end

Then in my view, I can call it like this

app/view/comments/comments.html.haml

- stack = resource.root_comments
- stack_helper(stack) do |comment, deep|
  .comments-show[comment]{"data-deep" => deep}
    = render 'comments/show', comment: comment, resource: resource

And I indent my comments in my css file

app/assets/stylesheet/comment.css

.comments-show[data-deep='0']{padding-left: 0px;}
.comments-show[data-deep='1']{padding-left: 10%;}
.comments-show[data-deep] {padding-left: 20%;}

To a fully example, I have implemented it here https://github.com/ningirsu/gign

Hope that help!

Ningirsu

DustinFisher commented 9 years ago

I know this is an older issue, but I will throw this up here if someone else comes across this and looking for an example.

I worked through pieces and parts I found across the web and got threading working. I put a guide together showing how to get up and running.

Here is the example I put together: acts_as_commentable_with_threading example

richardnpnb commented 8 years ago

DustinFisher's guide is well written. The best I have found for this gem.