Okay, so i\'ve got paperclip working, and I\'m trying to use the built in validator to make sure that the file uploaded
Obviously you solved this for yourself a long time ago, but for anyone who is looking for the answer, there is actually a way to do it within the provided validation.
Simple add your message like so:
validates_attachment :avatar,
:content_type => { :content_type => /image/, :message => "Avatar must be an image" },
:size => { :in => 0..2.megabytes, :message => "Avatar must be less than 2 megabytes in size" }
I ended up writing two custom validators. It's true that these do the same thing the paperclip validators do, but they fail prettier:
def avatar_is_a_image
if self.avatar?
if !self.avatar.content_type.match(/image/)
errors.add(:avatar, "Avatar must be an image")
end
end
end
def avatar_is_less_than_two_megabytes
if self.avatar?
if self.avatar.size > 5.megabytes
errors.add(:avatar, "Avatar must be less than 5 megabytes in size")
end
end
end