3
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

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244

3 Answers3

3

Nope. You need to set a custom message to get that format. You can see from the paperclip source that they convert the size to an integer number of bytes in human_size.

Andrew Haines
  • 6,574
  • 21
  • 34
2

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')

Dennis Best
  • 3,614
  • 3
  • 20
  • 31
1

Which version of the gem you use?
I had the same problem, updating it to 4.2 solved the problem (The function human_size is now using the ActiveSupport::NumberHelper.number_to_human_size function in order to make it readable)

guyaloni
  • 4,972
  • 5
  • 52
  • 92