# Validates\_length\_of :message not working

**URL:** <https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863>\
**Category:** Rails\
**Created:** [September 25, 2006, 4:43am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863 "2006-09-25T04:43:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 4:43am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/1 "2006-09-25T04:43:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 6:15am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/2 "2006-09-25T06:15:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 6:47am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/3 "2006-09-25T06:47:22Z")

</div>

no such luck…same result.

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 7:05am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/4 "2006-09-25T07:05:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 9:27am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/5 "2006-09-25T09:27:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 10:23am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/6 "2006-09-25T10:23:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/7 "2006-09-25T23:52:06Z")

</div>

any other ideas why :message is not working?

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [September 25, 2006, 8:17am UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/8 "2006-09-25T08:17:30Z")

</div>

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

hmph…

---

<div class="post-metadata">

**Author:** ![chadster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/46a35a/32.png) [@chadster](https://www.ruby-forum.com/u/chadster)\
**Post date:** [October 8, 2006, 8:13pm UTC](https://www.ruby-forum.com/t/validates-length-of-message-not-working/69863/9 "2006-10-08T20:13:26Z")

</div>

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
