Comments, replies and likes!

Img 1040
Steve Brewer
5 months ago

I've made some changes to comments so you can now reply to and like them. 

You can also now comment on a language or hackroom, which is new and more complicated than it sounds. 

Comments have a 'commentable', which is polymorphic and can be anything you like. In this case we add the relation to the language model as

has_many :comments, as: :commentable, polymorphic: true

This tells Rails all comments with this language added as a 'commentable' on a comment (the thing it belongs to), then add it to this languages list of comments. 

If you've no idea what I just said, it's because I explained it terribly! 

Anyway, likes are similar as they have a 'likeable', which at the moment can only be a comment. But in future you could add post likes as well. 

I've used render methods in the controller to render the like count partial with JavaScript passing the up to date likes count so when you click like, it creates your like for that comment and re-renders the partial that has the like count in it with the new amount. 

You can see the code for likes here

Comments

Sign in with GitHub to comment
Sign in