# How do I pass interpolation variables to AR validations?

**URL:** <https://www.ruby-forum.com/t/how-do-i-pass-interpolation-variables-to-ar-validations/190033>\
**Category:** Rails\
**Created:** [June 11, 2010, 8:03pm UTC](https://www.ruby-forum.com/t/how-do-i-pass-interpolation-variables-to-ar-validations/190033 "2010-06-11T20:03:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![clashcityrocker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@clashcityrocker](https://www.ruby-forum.com/u/clashcityrocker)\
**Post date:** [June 11, 2010, 8:03pm UTC](https://www.ruby-forum.com/t/how-do-i-pass-interpolation-variables-to-ar-validations/190033/1 "2010-06-11T20:03:22Z")

</div>

(Rails 2.3.8)

Say I have in config/locales/en.yml:

en:  
activerecord:  
attributes:  
foo:  
bar: ‘Long%{br}name’

Now, in HTML I can do:  
t(:‘activerecord.attributes.foo.bar’, :br =\> ‘  
’)

and in LaTeX:  
t(:‘activerecord.attributes.foo.bar’, :br =\> ‘\\’)

However, this is doomed to fail with AR validations, e.g.:

# Model

class Foo \< ActiveRecord::Base  
validates\_presence\_of :bar  
end

# View Error

I18n::MissingInterpolationArgument in Foo#create  
missing interpolation argument in “Long%{br}name” ({:count=\>“1”} given)

So how do I pass :br to ‘activerecord.attributes.foo.bar’ in the context  
of Foo?  
Or is my approach wrong altogether?

Thank you

---

<div class="post-metadata">

**Author:** ![clashcityrocker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@clashcityrocker](https://www.ruby-forum.com/u/clashcityrocker)\
**Post date:** [June 12, 2010, 9:44am UTC](https://www.ruby-forum.com/t/how-do-i-pass-interpolation-variables-to-ar-validations/190033/2 "2010-06-12T09:44:52Z")

</div>

Got this working by using Ruby hashes instead of YAML:

{  
:en =\> {  
:activerecord =\> {  
:attributes =\> {  
:foo =\> {  
:bar =\> lambda {|scope, opts| “Long#{opts[:br] || ’ '}name” }  
}  
}  
}  
}  
}
