Sha256: a9b0c72ff1634d421b1a7b3e95bb6c8f38cc7d08e42fcffcd1867ed213e4aff5

Contents?: true

Size: 1005 Bytes

Versions: 37

Compression:

Stored size: 1005 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    # Controller that manages the comment votes.
    #
    class VotesController < Decidim::Comments::ApplicationController
      before_action :authenticate_user!
      before_action :set_comment

      helper_method :comment

      def create
        raise ActionController::RoutingError, "Not Found" unless comment

        enforce_permission_to :vote, :comment, comment: comment

        Decidim::Comments::VoteComment.call(comment, current_user, weight: params[:weight].to_i) do
          on(:ok) do
            respond_to do |format|
              format.js { render :create }
            end
          end
          on(:invalid) do
            respond_to do |format|
              format.js { render :error }
            end
          end
        end
      end

      private

      attr_reader :comment

      def set_comment
        @comment = Decidim::Comments::Comment.find_by(id: params[:comment_id])
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-comments-0.27.9 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.8 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.7 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.6 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.10 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.9 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.5 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.8 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.4 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.3 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.7 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.5 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.2 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.1 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.4 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.0 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.3 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.0.rc2 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.27.0.rc1 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.26.2 app/controllers/decidim/comments/votes_controller.rb