link_to displaying html instead of link

Hello: I am learning to use Helpers in Rails 3. I have a project model with 'Name' attribute in it. I want to display all the Projects with a 'Show' link next to it. The Problem is instead of displaying a link for 'Show' it is displaying the html(<a href="/projects/1"><img alt="Show" src="/images/icons/show.png?1285276800" /></a>

CODE: --Here is my app/views/projects/index.html.erb

<title> <p> Projects </p></title> <%= render @projects %>


<div class="project"> <%= project_title_links(project) %> </div>


module PeopleHelper   def project_title_links(project)     content_tag :h1 do       [ project.title,      link_to_icon('show', project)       ].join(' ')     end   end end


module ApplicationHelper

  def link_to_icon(icon_name, url_or_object, options={})     link_to(image_tag("icons/#{icon_name}.png"),                       url_or_object,                       options)   end


helpers are automatically scrubbed in rails 3. Try adding .html_safe to the return value

Thanks for your response. I tried adding .html_safe to the following, but its still outputting the same.


<div class="project"> <%= project_title_links(project).html_safe %> </div>

Hi Ravi,

Its because with rails3 they have implemented script safety by default. If you want to print html/script codes you need to explicitly declare it. try this

<%= raw project_title_links(project) %>

should work



Although this will work, it seems like bad form to do this for helpers in the view.
IMO, if the helper is intended to return renderable html, it should. Simply add .html_safe to the end of .join() in your helper --> .join(' ').html_safe

Hope this helps

Perfect - that did it. Thank You so much for your help! I appreciate it.