I have just upgraded to Rails 4 (which may or may not be the issue.
In the past if I have wanted to use a variable within a div class name I have done something like the following.
<% my_class_name = "hello" %>
<div class = "#{my_class_name}">
..
</div>
(Obviously the variable would be set in the controller or be an instance of a collection)
However, when I do that now the output I see in the page source is exactly what has been wriiten i.e.
<div class = "#{my_class_name}">
and NOT
<div class = "hello">
Has something changed in rails 4 where this syntax is no longer valid? Or any other hints, greatly appreciated.
Interestingly when I use the following in a helper method, all is well...
content_tag(:div, class: "#{divclass}") do
You need to use an erb tag in your erb templates:
<div class="<%= my_class_name %>">
You need to enter the ERB/Ruby context using the <%
tag.
<% my_class_name = "hello" %>
<div class="<%= my_class_name %>">
..
</div>
#{}
is an interpolation inside an ERB/Ruby context.
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