Rails 6 Active Storage Image Variants

38 views Asked by At

I am encountering an ActiveRecord::NotNullViolation exception when trying to create an image variant using ActiveStorage in my Rails application. The issue arises specifically when I attempt to generate a resized variant of an image stored in Azure Blob Storage. Here is the relevant code snippet:

photo.variant(resize: "100x100").processed.service_url

The issue is that I load the images directly from active storage blob:

photo = (ActiveStorage::Blob.find_signed(@model.config['blob_id'])

I don't have a relation set with has_attachments and when I try to generate variants I get the error:


ActiveRecord::NotNullViolation Exception: PG::NotNullViolation: ERROR:  null value in column "record_id" of relation "active_storage_attachments" violates not-null constraint
DETAIL:  Failing row contains (84, image, ActiveStorage::VariantRecord, null, 145, 2024-02-28 11:13:34.68619, null).

is there any other way to generate variants that doesn't requrire database insertion or these type of checks, thank you in advance.

Text above explains everything

0

There are 0 answers