Adrian Serafin
Adrian Serafin

Reputation: 7715

How make this function html_safe?

I'm writing helper to render html table header

def display_standard_table(columns)
  content_tag :table do
    content_tag :thead do
      content_tag :tr do
        concat columns.collect { |column| content_tag(:th, 'Header'.html_safe) }
      end
    end
  end
end

The html output is escaped:

<table><thead><tr>&lt;th&gt;Header&lt;/th&gt;&lt;th&gt;Header&lt;/th&gt;</tr></thead></table>

How do I make it unescaped?

[SOLUTION]

def display_standard_table(columns, objects = [])
  content_tag :table do
    content_tag :thead do
      content_tag :tr do
        columns.collect { |column| content_tag(:th, column[:display_name]) }.join()
      end
    end
  end
end

Upvotes: 1

Views: 794

Answers (1)

Reactormonk
Reactormonk

Reputation: 21690

concat? use join on the mapped array and see what happens.

Upvotes: 2

Related Questions