Sha256: af94b9dc65006ae237704b7027cd85baa8cb0d268b608f0e60aeefdbcb7600e2

Contents?: true

Size: 998 Bytes

Versions: 18

Compression:

Stored size: 998 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:)

        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

18 entries across 18 versions & 1 rubygems

Version Path
decidim-comments-0.30.0.rc3 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.30.0.rc2 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.30.0.rc1 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.29.2 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.5 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.29.1 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.4 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.29.0 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.3 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.29.0.rc4 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.29.0.rc3 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.29.0.rc2 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.29.0.rc1 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.2 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.1 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.0 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.0.rc5 app/controllers/decidim/comments/votes_controller.rb
decidim-comments-0.28.0.rc4 app/controllers/decidim/comments/votes_controller.rb