Class: Decidim::DecidimAwesome::EditorImagesController

Inherits:
ApplicationController show all
Includes:
AjaxPermissionHandler, FormFactory
Defined in:
app/controllers/decidim/decidim_awesome/editor_images_controller.rb

Overview

This controller handles image uploads for the Tiptap editor

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#createObject



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

def create
  enforce_permission_to(:create, :editor_image, awesome_config:)

  @form = form(EditorImageForm).from_params(form_values)
  CreateEditorImage.call(@form) do
    on(:ok) do |image|
      url = image.attached_uploader(:file).path
      render json: { url:, message: I18n.t("success", scope: "decidim.editor_images.create") }
    end

    on(:invalid) do |_message|
      render json: { message: I18n.t("error", scope: "decidim.editor_images.create") }, status: :unprocessable_entity
    end
  end
end