'Rails 7 Active Storage attach multiple photos

After upgrading to Ruby 3 and Rails 7, I am unable to upload multiple attachments with Rails Active Storage:

Model

has_many_attached :photos

Service

#Fetch images from RETS API
def objects
  @objects ||= @client.objects(
    @count,
    resource: RESOURCE,
    object_type: OBJECT_TYPE,
    resource_id: sysid
  )
end

def photos
  @photos ||= objects.map do |data|
    Base64.decode64(Base64.strict_encode64(data.body))
  end
end

def attach_photos
  photo_array = []
  photos.each_with_index do |photo, index|
    photo_array << {
      io: StringIO.new(photo),
      filename: "#{filename}-#{index}.jpeg",
      content_type: 'image/jpeg'
    } 
  end

  Listing.photos.attach(photo_array)
end

Error

#<ArgumentError: wrong number of arguments (given 3, expected 0)>

What do I need to change in order to attach multiple files?



Solution 1:[1]

The temporary fix is to revert the Rails 7.0.1 upgrade to stable branch and install ruby-vips:

gem 'rails', git: 'https://github.com/rails/rails.git', branch: '7-0-stable'
gem 'ruby-vips'

You can follow this issue on Github: https://github.com/rails/rails/issues/43971.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AKN