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



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

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

#successful_uploader_response(file:, status: :created) ⇒ Object



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

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

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