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 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.
On Feb 11, 7:01 pm, Ralph S. [email protected] 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
Frederick C. wrote:
On Feb 11, 7:01�pm, Ralph S. [email protected] 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
[email protected]