Class: Decidim::Admin::CategoriesController

Inherits:
ApplicationController show all
Includes:
Decidim::Admin::Concerns::ParticipatoryProcessAdmin
Defined in:
app/controllers/decidim/admin/categories_controller.rb

Overview

Controller that allows managing categories.

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability_klass, #user_not_authorized_path

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/decidim/admin/categories_controller.rb', line 21

def create
  authorize! :create, Decidim::Category
  @form = form(CategoryForm).from_params(params, current_process: current_participatory_process)

  CreateCategory.call(@form, current_participatory_process) do
    on(:ok) do
      flash[:notice] = I18n.t("categories.create.success", scope: "decidim.admin")
      redirect_to participatory_process_categories_path(current_participatory_process)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("categories.create.error", scope: "decidim.admin")
      render :new
    end
  end
end

#destroyObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/decidim/admin/categories_controller.rb', line 67

def destroy
  @category = collection.find(params[:id])
  authorize! :destroy, @category

  DestroyCategory.call(@category) do
    on(:ok) do
      flash[:notice] = I18n.t("categories.destroy.success", scope: "decidim.admin")
    end

    on(:invalid) do
      flash[:alert] = I18n.t("categories.destroy.error", scope: "decidim.admin")
    end

    redirect_back(fallback_location: participatory_process_categories_path(current_participatory_process))
  end
end

#editObject



38
39
40
41
42
# File 'app/controllers/decidim/admin/categories_controller.rb', line 38

def edit
  @category = collection.find(params[:id])
  authorize! :update, @category
  @form = form(CategoryForm).from_model(@category, current_process: current_participatory_process)
end

#indexObject



12
13
14
# File 'app/controllers/decidim/admin/categories_controller.rb', line 12

def index
  authorize! :read, Decidim::Category
end

#newObject



16
17
18
19
# File 'app/controllers/decidim/admin/categories_controller.rb', line 16

def new
  authorize! :create, Decidim::Category
  @form = form(CategoryForm).from_params({}, current_process: current_participatory_process)
end

#showObject



62
63
64
65
# File 'app/controllers/decidim/admin/categories_controller.rb', line 62

def show
  @category = collection.find(params[:id])
  authorize! :read, @category
end

#updateObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/decidim/admin/categories_controller.rb', line 44

def update
  @category = collection.find(params[:id])
  authorize! :update, @category
  @form = form(CategoryForm).from_params(params, current_process: current_participatory_process)

  UpdateCategory.call(@category, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("categories.update.success", scope: "decidim.admin")
      redirect_to participatory_process_categories_path(current_participatory_process)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("categories.update.error", scope: "decidim.admin")
      render :edit
    end
  end
end