Class: Decidim::Consultations::QuestionVotesController

Inherits:
ApplicationController show all
Includes:
NeedsQuestion, FormFactory
Defined in:
decidim-consultations/app/controllers/decidim/consultations/question_votes_controller.rb

Instance Method Summary collapse

Methods included from NeedsQuestion

enhance_controller, extended, included

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'decidim-consultations/app/controllers/decidim/consultations/question_votes_controller.rb', line 13

def create
  enforce_permission_to :vote, :question, question: current_question

  vote_form = form(VoteForm).from_params(params, current_question: current_question)
  VoteQuestion.call(vote_form) do
    on(:ok) do
      current_question.reload
      render :update_vote_button
    end

    on(:invalid) do
      render json: {
        error: I18n.t("question_votes.create.error", scope: "decidim.consultations")
      }, status: :unprocessable_entity
    end
  end
end

#destroyObject


31
32
33
34
35
36
37
38
39
# File 'decidim-consultations/app/controllers/decidim/consultations/question_votes_controller.rb', line 31

def destroy
  enforce_permission_to :unvote, :question, question: current_question
  UnvoteQuestion.call(current_question, current_user) do
    on(:ok) do
      current_question.reload
      render :update_vote_button
    end
  end
end