# Help with String interpolation of ivar

**URL:** <https://www.ruby-forum.com/t/help-with-string-interpolation-of-ivar/203561>\
**Category:** Rails I18n\
**Created:** [February 23, 2011, 12:13am UTC](https://www.ruby-forum.com/t/help-with-string-interpolation-of-ivar/203561 "2011-02-23T00:13:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 23, 2011, 12:13am UTC](https://www.ruby-forum.com/t/help-with-string-interpolation-of-ivar/203561/1 "2011-02-23T00:13:56Z")

</div>

Suppose I have a model class like this:  
class Shoebox \< ActiveRecord::Base  
validates\_inclusion\_of :description, :in =\> [“small”, “medium”],  
:message =\> I18n.t(“activerecord.errors.models.shoebox.with\_name”,  
:name =\> name)  
end

And some yaml:  
en:  
activerecord:  
errors:  
models:  
shoebox:  
with\_name: “the description of %{name} is not in the approved list”

And I create a new Shoebox:  
s = Shoebox.new(:description =\> “large”, :name =\> “Bob”)  
s.valid?

But when I look at the error (s.errors.first.message), I see:  
“the description of Shoebox is not in the approved list”

and not:  
“the description of Bob is not in the approved list”

I’ve tried :name =\> name, , :name =\> :name, :name =\> lambda{name},  
:name =\> lambda{:name}.

I’ve tried creating a helper method  
def shoebox\_name  
name  
end

And passing :name =\> shoebox\_name, :name =\> :shoebox\_name, :name =\>  
lambda{shoebox\_name} and :name =\> lambda {:shoebox\_name}.

How can I get the ivar value for name to be interpolated into the  
string?

Paul
