class Message < ActiveRecord::Base | |
validate :image_size_validation, :if => Proc.new { |m| m.image.present? } | |
mount_uploader :image, MessageImageUploader | |
private | |
def image_size_validation | |
errors[:image] << "should be less than 2MB" if image.size > 2.megabytes | |
end | |
end |
This comment has been minimized.
This comment has been minimized.
Ah that's sugar, thanks! |
This comment has been minimized.
This comment has been minimized.
I took your basic idea and turned it into a Rails 3 style validator. It's basically a clone of the built-in validates_length_of validator, but checks the file size instead. https://gist.github.com/1009861 |
This comment has been minimized.
This comment has been minimized.
Cool, thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Replace this:
with that:
for cleaner code.