Class: Integral::Backend::StorageFilesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/integral/backend/storage_files_controller.rb

Overview

Storage files controller

Instance Method Summary collapse

Methods inherited from BaseController

#activities, #activity, #destroy, #duplicate, #edit, #index, #list, #update

Instance Method Details

#createObject

POST / Resource creation



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/integral/backend/storage_files_controller.rb', line 40

def create
  @resource = resource_klass.new(resource_params)

  if @resource.save
    resource_data = @resource.to_list_item
    resource_data[:image] = main_app.url_for(resource_data[:image].representation(Integral.image_transformation_options.merge!(resize_to_limit: Integral.image_sizes[:medium])))
    render json: resource_data, status: :created
  else
    head :unprocessable_entity
  end
end

#newObject

GET /new Resource creation screen



33
34
35
36
# File 'app/controllers/integral/backend/storage_files_controller.rb', line 33

def new
  add_breadcrumb I18n.t('integral.actions.upload')
  @resource = resource_klass.new
end

#showObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/integral/backend/storage_files_controller.rb', line 8

def show
  if params["_locale"].present?
    file = Integral::Storage::File.find(params[:id]).decorate
    res = {
      id: file.id,
      alt: file.title,
      link: "",
      caption: "",
      media_details: {
        sizes:  {
          large: {
            source_url: file.image_url(size: :large)
          }
        }
      },
    }

    render json: res, status: 200, layout: false
  else
    super
  end
end