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
# #attribute is a private method so we can't call it directly, that's why we use #send. | |
class DimensionsValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
if record.send("#{attribute}?".to_sym) | |
dimensions = Paperclip::Geometry.from_file(value.queued_for_write[:original].path) | |
width = options[:width] | |
height = options[:height] | |
record.errors[attribute] << "To πλάτος πρέπει να είναι #{width}px" unless dimensions.width == width |
NewerOlder