Created
January 25, 2011 21:08
-
-
Save jpemberthy/795665 to your computer and use it in GitHub Desktop.
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
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 |
Ah that's sugar, thanks!
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
Cool, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace this:
with that:
for cleaner code.