Topic: simple comment/reply system

Ok, so what i am planning to do is a just simple system where u can add comments to news. Thats all crear and simple. I need help to work out how to add reply function to the comments. So i added replied_comment_id to the comment table and now when someone replies to cooment then this comment id will be set to that field.

The question is: is that a good way of implemeting this? Or maybe someone have experience doing it?

Edit: found this thing -> http://stackoverflow.com/questions/4639 … -for-rails

And this looks exactly what i need, any thoughts?

Last edited by soend (2010-07-04 16:52:51)

Re: simple comment/reply system

Well you can set up associations within the same model, you just have to supply the foreign key.

# comment.rb
has_many :replies, :class_name => "Comment", :foreign_key => "replied_comment_id"

And to access them you would do comment.replies.

I guess this would only work for one layer of nested comments though, not deeply nested !

Or just use that acts_as_tree ^^

Last edited by Kentor (2010-07-04 16:56:38)

Re: simple comment/reply system

Thnx, for the reply. Looks like acts_as_tree is a good way out. Other solution would be use this http://github.com/aarongough/has_threaded_comments as well.

So many joices now afther finding that the magic word what to search is 'threaded' big_smile

Last edited by soend (2010-07-04 17:00:59)