recursive expansition of <% ... %>

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?

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.

Mat Brown 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:

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

Fred

Frederick Cheung 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,