Validate data

Can anyone help me??

I validate a form-field:

protected
def validate
errors.add(:name, “should be longer than 2 chars”) unless name.length
<= 2
end

I want to check the variable name. It should have a size over 2
characters. But my function “validate” doesn’t run! Why ???

On 8/8/06, Marco R. [email protected] wrote:

end
http://lists.rubyonrails.org/mailman/listinfo/rails

Could it be a typo? <= 2 instead of > 2

errors.add(:name, “should be longer than 2 chars”) unless name.length
<= 2

I want to check the variable name. It should have a size over 2
characters. But my function “validate” doesn’t run! Why ???
well I also vote for the typo… or anyway you have to put > 2 if you
want the error to be added using “unless”

Btw my suggestiong is to use the validates heaven:
validates_length_of :fav_bra_size, :minimum=>1, :too_short=>“please
enter at least %d character”

HTH
Enrico


“The only thing necessary for the triumph of evil
is for good men to do nothing”
Edmund Burke