3

I am using rails 5.2, active_storage with image_magic and minimagick for creating variants of different sizes, I am using the following code to generate the variants:

attachment.variant(combine_options: {
                          resize: "#{size}x#{size}^",
                          extent: "#{size}x#{size}",
                          gravity: 'center',
                          quality: 95 }
                        ).service_url

Variants are created successfully and loaded in browser using url generated by service_url method but on production is throwing following error:

enter image description here

It works perfectly fine if I don't create the variants.

Talha Junaid
  • 904
  • 1
  • 7
  • 15

1 Answers1

2

You need to call #processed on the variant so that Rails processes and uploads it. Rails v7.0:

has_one_attached :image do |attachable|
  attachable.variant :thumb, resize_to_limit: [100, 100]
end

def thumb_url
  image.variant(:thumb).processed.url if image.attached?
end

Docs

Felipe Zavan
  • 1,654
  • 1
  • 14
  • 33