for instance, an image field for a house for sale, if the user leaves
the image field empty, that means s/he has no picture, that could be
fine.
but, when s/he chooses submitting a pic, the pic file name must has
either .jpg, gif, or PNG ext.
I am using:
validates_format_of :image, :with=>/^.*(.jpg|.JPG|.gif|.GIF|.png|.PNG)$/
Well, if you want to validate the file name only, sure. Ultimately the file can be anything that the user names it, but here is how it’s done in the depot app from the rails book:
validates_format_of :image_url,
:with => %r{\.(gif|jpg|png)$}i,
:message => "must be a URL for a GIF, JPG, or PNG image"
Hi Saurav,
The :content_type => :image option on your has_attachment line will
limit it to "all standard image types" (which I think consists
of .gif, .png and .jpg). You can override this by passing it an
explicit list of MIME types: