I'm having a problem with active storage after upgrading rails version to 7.1.2. I am trying to run this code:
banner = Banner.new
img_url = "https://t3.ftcdn.net/jpg/04/75/78/56/360_F_475785604_HDtTcxBFA0Av87F7JoFmpircCcatQ22b.jpg"
picture = URI.open(img_url, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE})
banner.img_v2.attach(io: picture, filename: File.basename(picture), key: "banners/v2/#{File.basename(picture)}.png")
banner.save
And i am getting following error on banner.save
or banner.img_v2.url
:
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activestorage-7.1.2/app/models/active_storage/blob.rb:87:in `build_after_unfurling': wrong number of arguments (given 1, expected 0; required keywords: io, filename) (ArgumentError)
I found this issue closest to mine but it didn't help. Appreciate for any help or suggestion.
I figured out i was using an initializer for active storage which is compatible with rails 6. I find out the source code and the solution here.
The error comes from this line:
when Hash
ActiveStorage::Blob.build_after_unfurling({ metadata: { acl: acl } }.deep_merge(attachable))
Correction:
when Hash
ActiveStorage::Blob.build_after_unfurling \
io: attachable[:io],
filename: attachable[:filename],
content_type: attachable[:content_type],
metadata: { acl: acl }