Sha256: d7dda2d11440c4be59d0dc7e94d031e577ef954823fe5e585dff63464965cbce

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Polls
      class AnswersController < Decidim::Meetings::ApplicationController
        include Decidim::Meetings::PollsResources
        include FormFactory

        helper_method :question

        def create
          enforce_permission_to(:create, :answer, question:)
          @form = form(AnswerForm).from_params(params, question:, current_user:)

          CreateAnswer.call(@form, current_user, questionnaire) do
            # Both :ok and :invalid render the same template, because
            # validation errors are displayed in the template
            respond_to do |format|
              format.js
            end
          end
        end

        private

        def question
          @question ||= questionnaire.questions.find(answer_params[:question_id]) if questionnaire
        end

        def answer_params
          params.require(:answer).permit(:question_id, choices: [:body, :answer_option_id])
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-meetings-0.28.4 app/controllers/decidim/meetings/polls/answers_controller.rb
decidim-meetings-0.28.3 app/controllers/decidim/meetings/polls/answers_controller.rb
decidim-meetings-0.28.2 app/controllers/decidim/meetings/polls/answers_controller.rb
decidim-meetings-0.28.1 app/controllers/decidim/meetings/polls/answers_controller.rb
decidim-meetings-0.28.0 app/controllers/decidim/meetings/polls/answers_controller.rb
decidim-meetings-0.28.0.rc5 app/controllers/decidim/meetings/polls/answers_controller.rb
decidim-meetings-0.28.0.rc4 app/controllers/decidim/meetings/polls/answers_controller.rb