Weird rendering of .html.erb file
So I have this file:
<h1>Calendar view</h1>
<div class="events">
<% @events.each do |e| %>
<%= raw(e.content)%&开发者_Go百科gt;
<% end %>
</div>
<br />
<div class="messages">
<% @messages.each do |m| %>
<%= raw(m.content)%>
<% end %>
</div>
With @events and @messages being valid instance variables in the controller...but when I go to the page the html looks like this:
<h1>Calendar view</h1>
<div class="events">
<br>
<div class="messages">
This is another message test
</div
Event Content
</div>
I'm confused. Maybe I'm missing something obvious?
The problem is that raw()
will output raw HTML content. The Rails template engine will try to merge that with the .erb
template you supplied.
Therefore, if either m.content
or e.content
are malformed, you will most likely get unexpected output.
The best way would be to look for syntax errors, especially missing closing elements.
精彩评论