Sha256: 692364a9324d550370ad5e85c261e32e5844fefe1dc49576a5bc7d2b6b4472e6

Contents?: true

Size: 946 Bytes

Versions: 11

Compression:

Stored size: 946 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # Exposes the proposal vote resource so users can vote proposals.
    class ProposalVotesController < Decidim::Proposals::ApplicationController
      include ProposalVotesHelper

      helper_method :proposal

      before_action :authenticate_user!

      def create
        authorize! :vote, proposal

        proposal.votes.create!(author: current_user)
        @from_proposals_list = params[:from_proposals_list] == "true"
        render :update_buttons_and_counters
      end

      def destroy
        authorize! :unvote, proposal

        proposal.votes.where(author: current_user).delete_all
        @from_proposals_list = params[:from_proposals_list] == "true"
        render :update_buttons_and_counters
      end

      private

      def proposal
        @proposal ||= Proposal.where(feature: current_feature).find(params[:proposal_id])
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
decidim-proposals-0.0.8.1 app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-0.0.8.1 decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-proposals-0.0.7 app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-0.0.7 decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-proposals-0.0.6 app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-0.0.6 decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-proposals-0.0.5 app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-0.0.5 decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-0.0.4 decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-proposals-0.0.3 app/controllers/decidim/proposals/proposal_votes_controller.rb
decidim-0.0.3 decidim-proposals/app/controllers/decidim/proposals/proposal_votes_controller.rb