Reputation: 4686
<li class=<%= @page_name == "home" ? "active span2" : "span2" %>>
turns into:
<li class="active" span2>
When the statement evaluates true.
My expected result is:
<li class="active span2">
Any ideas why this happens?
Upvotes: 1
Views: 378
Reputation: 26193
The quotes within your tags are essentially declaring the contents within as String
objects. The output of the statement is a string, but the string will not be encapsulated in quotes. The value of the class attribute must be in quotes in order for the markup to be valid. Subsequently, you'll need to enclose the entire statement within double quotes:
<li class="<%= @page_name == 'home' ? 'active span2' : 'span2' %>">
Upvotes: 3
Reputation: 61427
The output of your statement is actually
<li class=active span2>
which will be turned to your output by most browsers, in an effort to correct invalid markup.
You'll want to have it render this way:
<li class="<%= @page_name == "home" ? "active span2" : "span2" %>">
Upvotes: 3