Is anyone working on ActiveStorage validation? hinted at validation a while ago, but I haven’t seen anything on the topic since.

Is anyone currently working on this? If not, would anyone be opposed to me having a go at it?


I’m using this gem GitHub - igorkasyanchuk/active_storage_validations: Do it like => validates :photos, attached: true, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: 500.kilobytes }, limit: { min: 1, max: 3 }, aspect_ratio: :landscape, dimension: { width: { in: 800..1600 }

1 Like

Steps to reproduce

Create model like:

class Project < ApplicationRecord has_one_attached :attachment end Toys R Us Credit Card

There is no way to validate if the attachment is present or check its content type, etc. If you need - you need to write own validates :some_method code.

Yep, I think having some builtin validations for content type etc would be very helpful. I think paperclip does this reasonably well and it would be nice for Active Storage to do the same. For beginner users it’s a bit risk to not validate attachments at all because it’s too hard.