Last active
December 15, 2018 16:14
-
-
Save huhn511/5bb56620679233b42fd55e599441b1dd to your computer and use it in GitHub Desktop.
Custom validation method to validate correct image types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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