Class: Decidim::Accountability::Admin::ResultsController
- Inherits:
-
ApplicationController
- Object
- Decidim::Admin::Components::BaseController
- ApplicationController
- Decidim::Accountability::Admin::ResultsController
- Includes:
- Filterable, Decidim::ApplicationHelper, SanitizeHelper
- Defined in:
- app/controllers/decidim/accountability/admin/results_controller.rb
Overview
This controller allows an admin to manage results from a Participatory Process
Instance Method Summary collapse
- #collection ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#collection ⇒ Object
14 15 16 17 |
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 14 def collection parent_id = params[:parent_id].presence @collection ||= Result.where(component: current_component, parent_id:).page(params[:page]).per(15) end |
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 26 def create :create, :result @form = form(ResultForm).from_params(params) CreateResult.call(@form) do on(:ok) do flash[:notice] = I18n.t("results.create.success", scope: "decidim.accountability.admin") redirect_to results_path(parent_id: result.parent_id) end on(:invalid) do flash.now[:alert] = I18n.t("results.create.invalid", scope: "decidim.accountability.admin") render action: "new" end end end |
#destroy ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 68 def destroy (:destroy, :result, result:) Decidim::Commands::DestroyResource.call(result, current_user) do on(:ok) do flash[:notice] = I18n.t("results.destroy.success", scope: "decidim.accountability.admin") redirect_to results_path(parent_id: result.parent_id) end end end |
#edit ⇒ Object
44 45 46 47 48 |
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 44 def edit (:update, :result, result:) @form = form(ResultForm).from_model(result) end |
#new ⇒ Object
19 20 21 22 23 24 |
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 19 def new :create, :result @form = form(ResultForm).instance @form.parent_id = params[:parent_id] end |
#update ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/decidim/accountability/admin/results_controller.rb', line 50 def update (:update, :result, result:) @form = form(ResultForm).from_params(params) UpdateResult.call(@form, result) do on(:ok) do flash[:notice] = I18n.t("results.update.success", scope: "decidim.accountability.admin") redirect_to results_path(parent_id: result.parent_id) end on(:invalid) do flash.now[:alert] = I18n.t("results.update.invalid", scope: "decidim.accountability.admin") render action: "edit" end end end |