Sha256: 7afb9176498602c54baab18c568d6de9820b7b3a11d8936c5769e960754ed268

Contents?: true

Size: 1.16 KB

Versions: 25

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      # This controller allows admins to answer proposals in a participatory process.
      class ProposalAnswersController < Admin::ApplicationController
        helper_method :proposal

        def edit
          enforce_permission_to :create, :proposal_answer
          @form = form(Admin::ProposalAnswerForm).from_model(proposal)
        end

        def update
          enforce_permission_to :create, :proposal_answer
          @form = form(Admin::ProposalAnswerForm).from_params(params)

          Admin::AnswerProposal.call(@form, proposal) do
            on(:ok) do
              flash[:notice] = I18n.t("proposals.answer.success", scope: "decidim.proposals.admin")
              redirect_to proposals_path
            end

            on(:invalid) do
              flash.now[:alert] = I18n.t("proposals.answer.invalid", scope: "decidim.proposals.admin")
              render action: "edit"
            end
          end
        end

        private

        def proposal
          @proposal ||= Proposal.where(component: current_component).find(params[:id])
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-proposals-0.20.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.20.0 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.19.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.18.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.19.0 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.17.2 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.18.0 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.17.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.16.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.17.0 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.16.0 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.15.2 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.15.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.15.0 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.14.4 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.14.3 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.14.2 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.14.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.13.1 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
decidim-proposals-0.12.2 app/controllers/decidim/proposals/admin/proposal_answers_controller.rb