I want to do the following in a form:
a field may either empty or something must be following the validation
if a user submit the form with the field empty, that’s fine. but if the
user submits something in the field, it must follow the validation
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
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)$/
to validate the pic, but my problem is, when a user leaves image empty,
the validation still does not allow to save the record.
how may I fix it? thanks.