Skip to content

Instantly share code, notes, and snippets.

@huhn511
Last active December 15, 2018 16:14
Show Gist options
  • Save huhn511/5bb56620679233b42fd55e599441b1dd to your computer and use it in GitHub Desktop.
Save huhn511/5bb56620679233b42fd55e599441b1dd to your computer and use it in GitHub Desktop.
Custom validation method to validate correct image types
has_one_attached :image
validate :image_type
private
def image_type
if image.attached? == false
errors.add(:image, "is missing!")
end
if !image.content_type.in?(%('image/jpeg image/png'))
errors.add(:image, "needs to be a jpeg or png!")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment