Module: Eluvia::AttachmentHelper

Extended by:
ActiveSupport::Concern
Included in:
File
Defined in:
lib/eluvia/helpers/attachment_helper.rb

Instance Method Summary collapse

Instance Method Details

#attachment_url(attachment, skip_check: false, expires_in: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/eluvia/helpers/attachment_helper.rb', line 5

def attachment_url(attachment, skip_check: false, expires_in: nil)
  unless skip_check
    return nil unless attachment.attached?
  end
  if Rails.application.config.active_storage.service == :local
    Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
  elsif expires_in
    attachment.url(expires_in: expires_in)
  else
    attachment.url
  end
  # NOTE: class method can't be called from instance method because of controller / view helpers, so we need to
  # duplicate the code here.
end