Rails syntax for comments in templates: is this bug understood?
- by brahn
Using rails 2.3.2 I have a partial _foo.rhtml that begins with a comment
as follows:
<% # here is a comment %>
<li><%= foo %></li>
When I render the partial from a view in the traditional way, e.g.
<% some_numbers = [1, 2, 3, 4, 5] %>
<ul>
<%= render :partial => "foo", :collection => some_numbers %>
</ul>
I found that the <li> and </li> tags are ommitted in the output -- i.e. the resulting HTML is
<ul> 1 2 3 4 5 </ul>
However, I can solve this problem by fixing _foo.rhtml to eliminate the space between
the <% and the # so that the partial now reads:
<%# here is a comment %>
<li><%= foo %></li>
My question: what's going on here? E.g., is <% # comment %> simply
incorrect syntax for including comments in a template? Or is the
problem more subtle?
Thanks!