class ActiveStorage::Attached

Attributes

name[R]
record[R]

Public Class Methods

new(name, record) click to toggle source
# File lib/active_storage/attached.rb, line 10
def initialize(name, record)
  @name, @record = name, record
end

Private Instance Methods

create_blob_from(attachable) click to toggle source
# File lib/active_storage/attached.rb, line 15
def create_blob_from(attachable)
  case attachable
  when ActiveStorage::Blob
    attachable
  when ActionDispatch::Http::UploadedFile
    ActiveStorage::Blob.create_after_upload! \
      io: attachable.open,
      filename: attachable.original_filename,
      content_type: attachable.content_type
  when Hash
    ActiveStorage::Blob.create_after_upload!(attachable)
  else
    nil
  end
end