Home > front end >  Active Storage delete variants from database and recreate
Active Storage delete variants from database and recreate

Time:12-19

I upgraded Active Storage to store variants record in database using

config.active_storage.track_variants: true

I duplicated some items with images and it caused broken variants I am generating variants like

item.image.variant(resize_to_limit= [800, nil]).processed

due to these broken variants/images I want to delete variant records from database while keeping original image, and than recreate variants

how can I only remove variants?

CodePudding user response:

To delete all variant records you can call

ActiveStorage::VariantRecord.delete_all

or

ActiveStorage::VariantRecord.destroy_all

To remove variants of specific item image like this

ActiveStorage::VariantRecord.where(blob_id: item.image.blob.id).delete_all

In your config probably you need to replace : with =

  • Related