1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activestorage/lib/active_storage/attached.rb
Jacopo a8a60652a3 Fix ActiveStorage has_many_attached when record is not persisted
This is a follow up of #42256.

Purging a not persisted record no longer raise an error for
`has_many_attached`.

Moves the `purge` and `purge_later` logic of `ActiveStorage::Attached`
to `Attached::Changes` API.
2021-06-12 19:49:21 +02:00

25 lines
666 B
Ruby

# frozen_string_literal: true
require "active_support/core_ext/module/delegation"
module ActiveStorage
# Abstract base class for the concrete ActiveStorage::Attached::One and ActiveStorage::Attached::Many
# classes that both provide proxy access to the blob association for a record.
class Attached
attr_reader :name, :record
def initialize(name, record)
@name, @record = name, record
end
private
def change
record.attachment_changes[name]
end
end
end
require "active_storage/attached/model"
require "active_storage/attached/one"
require "active_storage/attached/many"
require "active_storage/attached/changes"