Class: Decidim::Accountability::Admin::ProjectsImportController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/accountability/admin/projects_import_controller.rb

Overview

This controller allows an admin to import results from a csv file for the Accountability component

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/decidim/accountability/admin/projects_import_controller.rb', line 13

def create
  enforce_permission_to :create, :import_projects
  @form = form(Admin::ResultImportProjectsForm).from_params(params, accountability_component: current_component)
  Admin::ImportProjectsToAccountability.call(@form) do
    on(:ok) do |projects|
      flash[:notice] = I18n.t("projects_import.new.success", scope: "decidim.accountability.admin", count: projects)
      redirect_to results_path
    end

    on(:invalid) do
      flash[:alert] = I18n.t("projects_import.create.invalid", scope: "decidim.accountability.admin")
      render action: "new"
    end
  end
end

#newObject



8
9
10
11
# File 'app/controllers/decidim/accountability/admin/projects_import_controller.rb', line 8

def new
  enforce_permission_to :create, :import_projects
  @form = form(Admin::ResultImportProjectsForm).instance
end