diff --git a/app/models/concerns/image/attachment_extensions.rb b/app/models/concerns/image/attachment_extensions.rb index 71f29916..4d10c0d4 100644 --- a/app/models/concerns/image/attachment_extensions.rb +++ b/app/models/concerns/image/attachment_extensions.rb @@ -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 \ No newline at end of file