don''t know if using :minimum and :maximum would cause any problems,
but you could just use:
validates_length_of :state, :is => 2, :message => "Use the two-letter
state abbreviation"
or even
validates_format_of :state, :with => /^[a-zA-Z]{2}$/
that way you know you are getting a 2 character field that only
contains A-Z and or a-z characters.
Chris
On 8/17/06, Shauna <slhaines@gmail.com> wrote:> I am new to ruby/rails and am having a problem with validates_length_of.
> It seems to work fine on a varchar field, but when I try it on a char
> field the extra characters are silently truncated and the message
> appears that the record was successfully updated.
>
> How can I get my app to produce my error message instead? I''ve
tried
> various variations, but here''s one of my tries:
>
> validates_length_of :State, :minimum => 2, :maximum => 2,
> :message => "Use the two-letter state abbreviation"
>
> I know I can use a drop-down list instead (that''s my next
exercise) but
> I''d like to know how to do this for other char fields as well. Or
is the
> char issue a red herring and something else is wrong with my code?
>
> Thanks,
> Shauna
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>