Class: Decidim::Notify::ChaptersController

Inherits:
ApplicationController show all
Includes:
Broadcasts, NeedsAjaxRescue, FormFactory
Defined in:
app/controllers/decidim/notify/chapters_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#destroyObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/decidim/notify/chapters_controller.rb', line 26

def destroy
  enforce_permission_to :destroy, :chapter

  DeleteChapter.call(params[:id]) do
    on(:ok) do
      broadcast_destroy_chapter params[:id]
      render json: { message: "" }
    end
    on(:invalid) do |message|
      render json: { message: t("destroy.error", scope: "decidim.notify.chapter", message: message) }, status: :unprocessable_entity
    end
  end
end

#updateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/decidim/notify/chapters_controller.rb', line 10

def update
  enforce_permission_to :create, :chapter

  @form = form(ChapterForm).from_params(params)
  UpdateChapter.call(@form) do
    on(:ok) do |chapter, _old_title|
      broadcast_update_chapter chapter

      render json: { message: "" }
    end
    on(:invalid) do |message|
      render json: { message: t("update.error", scope: "decidim.notify.chapter", message: message) }, status: :unprocessable_entity
    end
  end
end