I validate a surname field like this
validates :surname,
:presence => true,
:length => { :within => min_surname_length..max_surname_length, :message => "is bad (minimum is #{min_surname_length}, maximum is is #{max_surname_length})" }
but I would like to separate cases when minimum and maximum without separate syntax validation like this
validates_length_of :name, :minimum => 3
validates_length_of :name, :maximum => 30
In few words, I would like to do something like this (I know, it is wrong):
validates :surname,
:presence => true,
:length => { :within => min_surname_length..max_surname_length,
:message =>开发者_StackOverflow中文版; "is bad (minimum is #{min_surname_length}" IF MINIMUM,
:message => "is bad (maximum is is #{max_surname_length})" IF MAXIMUM }
How it is possible to do that in one time?
SOLUTION
This is how I will use it:
validates :surname,
:length => { :within => min_password_length..max_password_length,
:too_short => 'too short message',
:too_long => 'too long message' }
validates_length_of :surname,
:within => 3..30,
:too_short => 'too short message',
:too_long => 'too long message'
精彩评论