Thani,

You can use :allow_nil, or :allow_blank to skip validation.

validates_format_of :email, :with => /whatever/, :allow_blank => true

# :allow_nil - If set to true, skips this validation if the attribute
is nil (default is false).
# :allow_blank - If set to true, skips this validation if the
attribute is blank (default is false).
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001639

You will probably want to use allow_blank because if you create an
email via params it could come back as an empty string.

--
Robert Zotter
Zapient, LLC
Ruby on Rails Development and Consulting

http://www.zapient.com
http://www.fromjavatoruby.com

On Nov 20, 4:42 am, Thani Ararsu <[EMAIL PROTECTED]>
wrote:
> in my User model i am using validations like this
>
> class User < ActiveRecord::Base
> validates_presence_of :email
> validates_format_of   :email ,:with=>/something/
>
> end
>
> if my email field is blank then i am getting 2 error messages
> but i want only one that should be first one (here it is presence)
>
> any idea?
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to