Abhishek
Abhishek

Reputation: 7045

Render <%= %> as a String in an .html.erb View?

I want to print following as a string in my .html.erb view.

<%= selected_color %>

So, I tried following in my file:

<h3><%= '<%= selected_color %>' %></h3>

It gave me following error:

syntax error, unexpected $undefined, expecting ')'

If I remove <%= '<%= selected_color %>' %> and place some string like abc, then it is printed on page without any issue.

As it is static page, I don't want to create a controller for it. So, can you help in showing that string on page?

p.s. I'm using ruby v1.9.3 and rails v3.1.0

Upvotes: 7

Views: 1899

Answers (2)

ex0ns
ex0ns

Reputation: 1116

You should double the % symbols as follow:

<h3><%%= rating_color %></h3>

Edit for source:

In erb.rb line 50, we see that <%% is a special tag that is replaced by <% we can also see that on line 650.

Upvotes: 9

kjmagic13
kjmagic13

Reputation: 1318

Pure HTML

&lt;%= selected_color %&gt;

or double % as mentioned by @ex0ns

<%%= selected_color %>

Upvotes: 3

Related Questions