Module: Alchemy::Admin::UploaderResponses

Extended by:
ActiveSupport::Concern
Included in:
AttachmentsController, PicturesController
Defined in:
app/controllers/concerns/alchemy/admin/uploader_responses.rb

Instance Method Summary collapse

Instance Method Details

#failed_uploader_response(file:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/concerns/alchemy/admin/uploader_responses.rb', line 18

def failed_uploader_response(file:)
  message = Alchemy.t(:upload_failure,
    scope: [:uploader, file.class.model_name.i18n_key],
    error: file.errors[:file].join,
    name: file.name
  )

  {
    json: uploader_response(file: file, message: message),
    status: :unprocessable_entity
  }
end

#succesful_uploader_response(file:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/concerns/alchemy/admin/uploader_responses.rb', line 6

def succesful_uploader_response(file:)
  message = Alchemy.t(:upload_success,
    scope: [:uploader, file.class.model_name.i18n_key],
    name: file.name
  )

  {
    json: uploader_response(file: file, message: message),
    status: :created
  }
end