Class: Glib::BlobUrlGeneratorsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/glib/blob_url_generators_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/glib/blob_url_generators_controller.rb', line 18

def create
  # Same failure class as the upload fields' `url_for(attachment)` (see
  # AbstractField#existing_attachment_url): `rails_blob_path` resolves
  # through ActiveStorage's default routes, so in apps that disable those
  # this endpoint would 500 in exactly and only the environments with the
  # routes off. Fail with a teaching error instead.
  unless ::ActiveStorage.draw_routes
    raise 'the default blob URL generator returns `rails_blob_path`, which resolves through ' \
          "ActiveStorage's default routes, and this app does not draw them " \
          '(config.active_storage.draw_routes = false). Point `blobUrlGenerator:` at an app ' \
          'endpoint that returns an authorized URL instead.'
  end

  blob = ::ActiveStorage::Blob.find_signed(params[:signed_id])
  url = blob.present? ? rails_blob_path(blob) : nil

  render json: { url: url }
end