-
Notifications
You must be signed in to change notification settings - Fork 216
Upvote and downvote a Scenario
Anoob Bava edited this page Jun 4, 2016
·
6 revisions
if we have the model Post model class Post < ApplicationRecord acts_as_votable end
now we need to update the routes resources :posts do member do put "like", to: "posts#upvote" put "dislike", to: "posts#downvote" end end
def upvote
@post.upvote_by current_user
redirect_to @post
end
def downvote
@post.downvote_by current_user
redirect_to @post
end
<%=link_to like_post_path(@post), method: :put, class: 'btn btn-default btn-sm' do %> like <%=@post.get_upvotes.size%> <% end %> <%=link_to dislike_post_path(@post), method: :put, class: 'btn btn-default btn-sm' do %> dislike <%=@post.get_downvotes.size%>