Hi all,
I want to provide the most meaningful error message possible when a
user enters the wrong data, so I have a series of validation rules like
so:
validates_presence_of :name
validates_length_of :name,
:in => 3..30
validates_format_of :name,
:with => /^[a-z]/i,
:message => ''begins with a non alphabetical
character''
validates_format_of :name,
:with => /^([a-z][a-z0-9_-]*)$/i,
:message => ''contains non alphanumeric
characters''
validates_uniqueness_of :name
Problem is when one is wrong I''d only like for the first error to be
shown, not all of them. I can use an :if => condition type clause but
I''m not sure how to do it without duplicating a lot, i.e. (pseudo code)
validates_presence_of :name
validates_length_of :name,
:if => not name.nil?,
:in => 3..30
validates_format_of :name,
:with => /^[a-z]/i,
:if => not name.nil? and name in 3..30,
:message => ''begins with a non alphabetical
character''
Any ideas?
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---