File column validates_format_of


#1

Been manually testing file column with success except it seems to upload
the file before validating it. Also .pdf files (which shouldn’t even
validate) crash WEBrick. What am I missing to solve these problems?
(apart from a brain!)

validates_presence_of :title, :file
validates_format_of :file, :with => %r{.(gif|jpg|png)$}i,
:message => “File must end with .jpg, .gif or .png”
file_column :file, :magick => {
:versions => { “thumb” => “100x100”, “medium” => “640x480>” }
}

end


#2

It’s my understanding that file_column always uploads the file no matter
what… it puts it in a temp location so that if there are errors on
any of
the other fields, your user won’t need to upload the file again.
Therefore I
don’t think you’ll be able to do what you want to do in quite the way
you’ve
attempted.

A quick glance through the file_column docs shows that there is an
optional
parameter that allows you to set extensions, although its actual use is
not
documented.

Your crash is most likely caused because it can’t resize a pdf with
RMagick
:slight_smile: