开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜