Sha256: 5e93848ef4146f4f168c7fb0a4f5452096c688db2953cdb65e67e4bac821405c

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  module Plans
    module Admin
      # This controller allows admins to answer plans in a participatory process.
      class PlanAnswersController < Admin::ApplicationController
        helper_method :plan

        def edit
          enforce_permission_to :create, :plan_answer
          @form = form(Admin::PlanAnswerForm).from_model(plan)
        end

        def update
          enforce_permission_to :create, :plan_answer
          @form = form(Admin::PlanAnswerForm).from_params(params)

          Admin::AnswerPlan.call(@form, plan) do
            on(:ok) do
              flash[:notice] = I18n.t("plans.answer.success", scope: "decidim.plans.admin")
              redirect_to plans_path
            end

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

        private

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-plans-0.18.2 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.18.1 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.18.0 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.17.0 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.9 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.8 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.7 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.6 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.5 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.4 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.3 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.2 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.1 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.16.0 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.15.1 app/controllers/decidim/plans/admin/plan_answers_controller.rb
decidim-plans-0.15.0 app/controllers/decidim/plans/admin/plan_answers_controller.rb