Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, Why does this helper not output HTML, but rather HTML in quotes?

I have the following helper in my application_helper.rb file:

  def topmenu
    pages = {
      "projects" => projects_path,
      "photos" => photos_path
    }
    pages.map do |key, value|
      classnames = %( class="current") if controller.controller_name == key
      "<li#{classnames}>#{link_to(key, value)}</li>"
    end
  end

Then in my application.html.erb file I have:

<%= topmenu %>

For some reason, the page is generating showing the HTML from the above helper as TEXT, not HTML. Not sure why? thx

like image 219
AnApprentice Avatar asked Oct 07 '10 05:10

AnApprentice


1 Answers

I presume you're running rails3. Add .html_safe method call before returning the string:

"<li#{classnames}>#{link_to(key, value)}</li>".html_safe
like image 92
Eimantas Avatar answered Nov 01 '22 17:11

Eimantas