# Recursive expansition of \<% ... %\>

**URL:** <https://www.ruby-forum.com/t/recursive-expansition-of/183325>\
**Category:** Rails\
**Created:** [February 11, 2010, 7:43pm UTC](https://www.ruby-forum.com/t/recursive-expansition-of/183325 "2010-02-11T19:43:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 11, 2010, 7:43pm UTC](https://www.ruby-forum.com/t/recursive-expansition-of/183325/1 "2010-02-11T19:43:52Z")

</div>

In a controller I have  
@message = “The size is \<% @a.size %\>.”

In the view I have

\<%= @message %\>

which, sadly, produces  
The size is \<% @a.size %\>.

rather than, say,  
The size is 4.

If I try  
\<%= \<%= @ message %\> %\>  
I get a syntax error.

Is there a solution?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 11, 2010, 7:48pm UTC](https://www.ruby-forum.com/t/recursive-expansition-of/183325/2 "2010-02-11T19:48:58Z")

</div>

The \<% … %\> style of interpolation is specific to ERB templates;  
it’s not used to interpolate in Ruby strings. What you’re looking for  
is:

@message = “The size is #{@a.size}”

I suggest familiarizing yourself with Ruby before diving into Rails.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 11, 2010, 8:01pm UTC](https://www.ruby-forum.com/t/recursive-expansition-of/183325/3 "2010-02-11T20:01:19Z")

</div>

Mat B. wrote:

> The \<% … %\> style of interpolation is specific to ERB templates;  
> it’s not used to interpolate in Ruby strings. What you’re looking for  
> is:
> 
> @message = “The size is #{@a.size}”
> 
> I suggest familiarizing yourself with Ruby before diving into Rails.

Ok … I tried to make my problem too simple. Stupid me.

The real problem is closer to this:

* * *

Controller:  
@message = I18n.t(‘some\_msg\_id’)

* * *

somefile.yml:  
some\_msg\_id: “The size is #{@a.size}”

* * *

view:  
\<%= @message %\>

* * *

How do I do what I want to do. I want to do the interpolation in the  
view and not beforehand.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 11, 2010, 10:34pm UTC](https://www.ruby-forum.com/t/recursive-expansition-of/183325/4 "2010-02-11T22:34:39Z")

</div>

On Feb 11, 7:01 pm, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do I do what I want to do. I want to do the interpolation in the  
> view and not beforehand.

The I18n stuff has a convention for interpolation - take a look at the  
docs

Fred

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 11, 2010, 10:42pm UTC](https://www.ruby-forum.com/t/recursive-expansition-of/183325/5 "2010-02-11T22:42:45Z")

</div>

Frederick C. wrote:

> On Feb 11, 7:01ï¿½pm, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > How do I do what I want to do. ï¿½I want to do the interpolation in the  
> > view and not beforehand.
> 
> The I18n stuff has a convention for interpolation - take a look at the  
> docs

Also check out fast\_gettext. To me, at least, it’s a lot nicer.

> Fred

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
