Validates_length_of :message not working

I have the following code:

validates_length_of :city, :within => 1…30, :message => “Your city
can’t be
blank”

But the error message keeps showing the default message “City is too
short
(minimum is 1 characters)”. It works fine if I set :too_short and
:too_long
but that’s extra coding (I’m picky with DRY).

Any idea why this might be?

Thanks,

Chad

On Sep 24, 2006, at 8:38 PM, Chad A. wrote:

validates_length_of :city, :within => 1…30, :message => “Your city
can’t be blank”

Try putting parentheses around 1…30.

validates_length_of :city, :within => (1…30), :message => “Your city
can’t be blank”

Aaron

no such luck…same result.

I just looked at the API and your original line looks like it should
work. The configuration options state that message is an alias of
too_long/too_short.

What happens if you just remove the message like this:

validates_length_of :city, :within => 1…30

In that case the default too_long/too_short messages are supposed to
kick in.

Aaron

if you don’t want the field to be blank, put

validates_presence_of :city, :message => ‘city cannot be blank’

and then, also,

validates_length_of :city . . . .

i presume that should be enough? what you are doing should be
working…the above should be enough, no?

harp

it IS working, just not how I’d expect. the :message isn’t being used
when I provide a :within attribute

any other ideas why :message is not working?

ya according to the API it’s supposed to work… hence my confusion.

hmph…

Chad wrote:

any other ideas why :message is not working?

No idea, but same problem. I’m running:

actionmailer (1.2.5, 1.2.1, 1.2.0)
Service layer for easy email delivery and testing.

actionpack (1.12.5, 1.12.1, 1.12.0)
Web-flow and rendering framework putting the VC in MVC.

actionwebservice (1.1.6, 1.1.2, 1.1.0)
Web service support for Action Pack.

activerecord (1.14.4, 1.14.2, 1.14.0)
Implements the ActiveRecord pattern for ORM.

activesupport (1.3.1, 1.3.0)
Support and utility classes used by the Rails framework.

rails (1.1.6, 1.1.2, 1.1.0)
Web-application framework with template engine, control-flow layer,
and ORM.

Todd

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs