I am using Rails 3. I am trying to do this in a helper:
def headers collection
collection.each do |col|
content_tag(:th, col.short_name)
end
end
As you can see, the idea is that this does a content_tag to generate a <th> tag for each element in the collection. This doesn’t work because the HTML comes out as is made safe by Rails which makes it not work as HTML.
If I change it to this:
def headers collection
collection.each do |col|
concat (content_tag(:th, col.short_name))
end
end
This works better. I get the correct markup in HTML, but before it I get all the markup HTML safe. So I think I am close.
I know there are other ways to do this but I wanted to try to do this in the right elegant way. What am I missing?
You could use inject and start with an html_safe empty string.