I have an application where I want to render the menu using "content_for" as well as a left navigation bar and then the rest be the body of my document. However, in my left bar and menu regions, the html markup is being escaped. I saw a post regarding using raw before the yield, but that didn't help.
After spending quite some time trying to diagnose it within the real app, I created a VERY simple test and was able to get it to do the same with minimal code. Here is what I have:
layouts.application.erb
<body>
<section id="page">
<header>
<nav class="clear"><%= raw yield :navigation %></nav>
</header>
<%= yield %>
</section>
</body>
</html>
pages/index.html.erb
<% content_for :navigation do %>
<ul><li><%= link_to 'New page', new_page_path %></li></ul>
<% end %>
<h1>Listing pages</h1>
<table>
<tr>
<th>Title</th>
<th>Body</th>
</tr>
<% @pages.each do |page| %>
<tr>
<td><%=h page.title %></td>
<td><%=h page.body %></td>
<td><%= link_to 'Show', page %></td>
<td><%= link_to 'Edit', edit_page_path(page) %></td>
<td><%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
When I hit the page in a browser, the navigation part is not escaped properly (actually the link is, but not the list, which is kinda important with menus:) )
This is from a brand new rails project using scaffold generated code which was modified only to move the default link up into the navigation section (and adding that piece in).
The escaping is happening when you set aside the content, not when you display it. Try using
raw
withincontent_for
: