Even if pretty much nobody uses a browser with JavaScript disabled when navigating our sites, there might be times where JavaScript isn't loaded for reasons like a slow internet connections not getting the JavaScript files or a technical issue. So we're making it possible to still use the like/unlike buttons in these cases.
27 lines
813 B
Ruby
27 lines
813 B
Ruby
module Debates
|
|
class VotesController < ApplicationController
|
|
before_action :authenticate_user!
|
|
load_and_authorize_resource :debate
|
|
load_and_authorize_resource through: :debate, through_association: :votes_for, only: :destroy
|
|
|
|
def create
|
|
authorize! :create, Vote.new(voter: current_user, votable: @debate)
|
|
@debate.register_vote(current_user, params[:value])
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.create.vote") }
|
|
format.js { render :show }
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@debate.unvote_by(current_user)
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.destroy.vote") }
|
|
format.js { render :show }
|
|
end
|
|
end
|
|
end
|
|
end
|