Validate attribute only if it present (only if user fill in it)

Solution 1:

Add :allow_blank => true and it should do what you want.

Solution 2:

Maybe :if => lambda {|attr| attr.present?} will help?

Solution 3:

Some validations accept the options :allow_blank => true or :allow_nil => true.

If this fails, use :if condition, like this:

validates_format_of :avatar_file_name, 
 :with=>/\.(jpeg|jpg|png|gif)$/i, 
 :message=> I18n.t("..."), 
 :on => :update,
 :if => lambda{ |object| object.avatar_file_name.present? }

But i encourage you to use allows. Much cleaner.