# Testing error\_messages rails 2.3

**URL:** <https://www.ruby-forum.com/t/testing-error-messages-rails-2-3/171144>\
**Category:** Rails\
**Created:** [June 26, 2009, 11:56pm UTC](https://www.ruby-forum.com/t/testing-error-messages-rails-2-3/171144 "2009-06-26T23:56:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dream\_runner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dream\_runner](https://www.ruby-forum.com/u/dream_runner)\
**Post date:** [June 26, 2009, 11:56pm UTC](https://www.ruby-forum.com/t/testing-error-messages-rails-2-3/171144/1 "2009-06-26T23:56:18Z")

</div>

Quick question.

I’m kind of a novice to Rails and have been teaching myself using  
RailsSpace which has examples based on an older version of Ruby/Rails.  
I’ve been able to adapt them all but there was one question I had  
regarding testing error\_messages. I’ve noticed that the error\_messages  
in activeRecord have been changed due to internationalization. Not only  
that but in previous versions of Rails, the error message strings were  
of the form

:too\_short = “…(minimum is %d characters)”

Which made it easy to print with the correct value by using  
sprintf(@error\_messages[:too\_short], 15)

But it seems that now they are of the form:  
:too\_short = “…(minimum is {{count}} characters)”

Which cannot be as simply processed. They only way I’ve dealt with this  
is to use:

min\_length = 15  
@error\_messages[:too\_short]["{{count}}"] = “#{min\_length}”

I’m wondering if there is, it seems like there would be, an easier way  
of replacing the {{count}} portion of the error string.

Any help would be greatly appreciated on this.

---

<div class="post-metadata">

**Author:** ![dream\_runner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@dream\_runner](https://www.ruby-forum.com/u/dream_runner)\
**Post date:** [June 27, 2009, 8:17pm UTC](https://www.ruby-forum.com/t/testing-error-messages-rails-2-3/171144/2 "2009-06-27T20:17:03Z")

</div>

If you’re manually formatting validation error messages, you’re  
probably working too hard. Take a look at the documentation for  
ActiveRecord::Errors#generate\_message to handle this.

–Matt J.

On Jun 26, 5:56 pm, Arthur Mr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
