Rails 3 cleaning sub menu html

I have some code to allow pages to define sub menus within their
respective html files. Here’s the method I have in the application

def sub_menu(&block)
links ||= []
links << capture(&block)
@sub_menu ||= “”

links.each do |link|
  @sub_menu += content_tag(:li, link)

@sub_menu = content_tag(:ul, @sub_menu, :class => "side_menu")
@sub_menu = content_tag(:div, @sub_menu, :class =>


# concat @sub_menu


In an html file, I can define sub menus like this:

<% content_for :sub_menu do %>
<% sub_menu do %>
New story!
<% end %>
<% end %>

This worked in Rails 2, but in Rails 3 it just displays the HTML
instead of parsing it, and when I look in the source the HTML is
cleaned. Here’s an example:

<li> <a href="/stories/new"
class="side_button"><img src="/images/
new_story_button.png" class="centered" alt="New
story!" /></a>

How do I get around this?

Sounds like you need to call .html_safe on the return value of your
helper. In Rails 3, everything is automatically scrubbed.

fyi, you can also pass the content into the raw() function.

Thanks for the replies! I tried both ways and oddly enough they didn’t

On Dec 21, 11:08am, Garrett L. [email protected]