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
You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .
ERB is a templating engine. A templating engine allows you to mix HTML & Ruby so you can generate web pages using data from your database.
erb is by definition "embedded ruby", you can embed every ruby code between: <%= and the other: %> , typically all written in one line. In addition, ruby one-line comments start always with # , so the <%=# Comment %> style matches perfectly with both pure-ruby and erb styles for one-line comments.
You should double the %
symbols as follow:
<h3><%%= rating_color %></h3>
In erb.rb line 50, we see that <%%
is a special tag that is replaced by <%
we can also see that on line 650.
Pure HTML
<%= selected_color %>
or double % as mentioned by @ex0ns
<%%= selected_color %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With