Created
May 10, 2020 17:33
-
-
Save almokhtarbr/535bd0f29fe35798d5ec406b91c964cd to your computer and use it in GitHub Desktop.
validates image with active storage
This file contains 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
validate :acceptable_image | |
def acceptable_image | |
return unless main_image.attached? | |
end | |
def acceptable_image | |
return unless main_image.attached? | |
unless main_image.byte_size <= 1.megabyte | |
errors.add(:main_image, "is too big") | |
end | |
end | |
def acceptable_image | |
return unless main_image.attached? | |
unless main_image.byte_size <= 1.megabyte | |
errors.add(:main_image, "is too big") | |
end | |
acceptable_types = ["image/jpeg", "image/png"] | |
unless acceptable_types.include?(main_image.content_type) | |
errors.add(:main_image, "must 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