Module: ActiveStorage::BlobWithPreviewUrl

Defined in:
lib/active_storage/blob_with_preview_url.rb

Constant Summary collapse

PREVIEW_SIZE =
[ 1024, 768 ]

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/active_storage/blob_with_preview_url.rb', line 5

def as_json(options = nil)
  json = super(options)

  if previewable?
    json["previewable"] = true
    json["url"] = Rails.application.routes.url_helpers.rails_representation_path(
      preview(resize_to_limit: PREVIEW_SIZE), ActiveStorage::Current.url_options.merge(only_path: true)
    )
  end

  json
end