module RailsCom::AttachedOne

Public Instance Methods

attached?() click to toggle source
# File lib/rails_com/active_storage/attached_macros.rb, line 14
def attached?
  attachment&.id?
end
attachment() click to toggle source
Calls superclass method
# File lib/rails_com/active_storage/attached_macros.rb, line 3
def attachment
  if super
    return super
  elsif defined?(@attachment)
    return @attachment
  end

  id = ActiveStorage::BlobDefault.defaults["#{record.class.name}_#{name}"]
  @attachment = build_attachment(blob: ActiveStorage::Blob.find(id)) if id
end