Search code examples
ruby-on-rails-3paperclippaperclip-validation

Paperclip file size validation error message


validates_attachment_size :image, :less_than => 5.megabytes

gives an error message of

Image file size must be less than 5242880 Bytes

This isn't very user friendly.. Is there a way to make the message to be

Image file size must be less than 5 MB 

? without setting a custom message on my own


Solution

  • Actually, you can.

    I just added a message.

    validates_attachment_size :cover_image, :in => 0.megabytes..6.megabytes, :message => 'must be smaller than 6mb'
    

    My error is now: 'Cover_image must be smaller than 6mb.'

    (Would be nice if I could change 'Cover_image' so something more user-friendly. But still beats 'Cover_image file size must be less than 5242880 Bytes')