Add has_one_attached_with_default

This commit is contained in:
Eric 2020-05-15 12:10:07 -05:00
parent afecb1d63f
commit 60eb01c2ee

View file

@ -36,5 +36,15 @@ module Image::AttachmentExtensions
end
RUBY
end
def has_one_attached_with_default(attribute_name, default_path, **options)
after_save do
attribute = send(attribute_name)
unless attribute.attached?
attribute.attach(io: File.open(default_path), **options)
end
self
end
end
end
end