I have something like this:
<p>
<b>Tags:</b>
<%if @post.tags.count > 0%>
<%= @post.tags.collect {|c| (link_to c.name, c)}.join(", ")%>
<%else%>
Does not have any tags.
<%end%>
</p>
Which gives me
Tags: <a href="/tags/1">Java</a>, <a href="/tags/2">CSS</a>
Instead of Java and CSS links. What am I missing?
It’s because strings in Rails 3 are, by default, not considered HTML-safe. See this blog post about it.
You can manually mark something as safe by calling
.html_safeon it, which would make your code like so:But I’d recommend doing this instead: