I am trying to add the acts_as_votable to like post comments on my rails 5 app.
The gem was installed fine, I added two migrations (ActsAsVotable and AddCachedLikesToVotes) and to my CommentsController
I added:
def like
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
end
def vote
if !current_user.lked? @comment
@comment.liked_by current_user
elsif current_user.liked? @comment
@comment.unliked_by current_user
end
end
I then added this to my comment partial view:
<%= link_to like_post_comment_path(@post, comment), class: "like-btn", method: :put, remote: :true do %>
My error is for the above line. It's saying that:
No route matches {:action=>"vote", :controller=>"comments", :id=>nil, :post_id=>"1"} missing required keys: [:id]
The like_post_comment_path
is correct and I've tried different variations between (@post, comment)
, (@comment.post_id, comment)
, (@post, @comment)
, etc. and nothing works!