Radio Bantik:
Days in the Life of an Alpha Geek

Radio Bantik is an alpha-geek blog covering topics in Mac OS X, software and web development including Ruby on Rails, Java, Cocoa, and WebObjects, corporate survival, LEGO robotics, and other stuff important in the life of a technologist.

File_column bug with case sensitivity

Posted March 4th, 2008 in Ruby on Rails | Permanent Link

After banging my head against a wall wondering why certain image uploads would silently fail, while others succeeded, I stumbled across a file_column bug (and yes, I reported it).

If you have the following in your model:

validates_file_format_of :image, :in => ["bmp", "gif", "jpg", "pdf", "png"]

And you upload a file with one of these extensions in a different case, for example “SAMPLE.JPG”, the file format validation fails.

Workaround (non-DRY): add case variations, like this:

validates_file_format_of :image, :in => ["bmp", "gif", "jpg", "pdf", "png", "BMP", "GIF", "JPG", "PDF", "PNG"]

Grr.


Leave a Reply