class VotesController < ApplicationController
...
def show
@comment = Comment.find(params[:comment_id])
@vote = Vote.find_or_create_by(user: current_user, comment: @comment)
@vote.voted(params[:choice])
endclass Vote < ApplicationRecord
...
def voted(choice)
return unless choice.in?(Vote::choices.keys)
case choice
when 'up_vote'
up_vote? ? cancel! : up_vote!
when 'down_vote'
down_vote? ? cancel! : down_vote!
end
end