Files
nairobi/app/models/concerns/has_attachment.rb
Javi Martín 8eea6f585a Remove hack to allow IO files in Active Storage
We were using this hack in order to allow `File.new` attachments in
tests files. However, we can use the `fixture_file_upload` helper
instead.

Just like it happened with `file_fixture`, this helper method doesn't
work in fixtures, so in this case we're using `Rack::Test::UploadedFile`
instead.
2022-02-23 19:00:33 +01:00

18 lines
334 B
Ruby

module HasAttachment
extend ActiveSupport::Concern
class_methods do
def has_attachment(attribute)
has_one_attached attribute
define_method :"#{attribute}=" do |file|
if file.nil?
send(attribute).detach
else
send(attribute).attach(file)
end
end
end
end
end