validates_length_of not working with :if ?

validates_presence_of :nickname
validates_length_of :nickname, :in => 4…40, :allow_nil => true

but just make sure that you change the nickname param from “” [empty string] to nil or it won’t work. “”.nil? => false. I dunno why there’s not a :allow_blank => true which could cover nil? and empty?

RSL

Perhaps you have other errors? I dunno how else to help. Here’s the API page for validates_length_of which clearly states that :allow_nil is a valid parameter.

http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000942

Sigh.

RSL