8

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

2 Answers 2

25

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

"<li#{classnames}>#{link_to(key, value)}</li>".html_safe
Sign up to request clarification or add additional context in comments.

Comments

-2

It makes the code more clean? Isn't it? And you can do more thing in the help function(because it is not only a html)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.