title: rails, How to build table in helper using content_tag?
body: <p>I defined function in application helper:</p>
  
  <pre><code>def display_standard_table(columns, collection = {})    
    content_tag :table do      
      concat content_tag :thead do
        content_tag :tr do
          concat columns.collect { |column| content_tag(:td, column[:display_name]) }
        end
      end      
  
      concat content_tag :tbody do
        collection.collect { |elem| 
          concat content_tag(:tr, columns.collect { |column|
            content_tag(:td, elem.attributes[column[:name]])
        })
      }
      end
    end
  end
  </code></pre>
  
  <p>and I call it in my view:</p>
  
  <pre><code>&lt;%= display_standard_table(
            [
              { :name =&gt; 'id', :display_name =&gt; 'Id' },
              { :name =&gt; 'login', :display_name =&gt; 'Login' },
              { :name =&gt; 'first_name', :display_name =&gt; 'Name' },
              { :name =&gt; 'last_name', :display_name =&gt; 'LastName' },
              { :name =&gt; 'email', :display_name =&gt; 'Email'}
            ], @users) %&gt;
  </code></pre>
  
  <p>The output in html is:</p>
  
  <pre><code>&lt;table&gt;&lt;thead&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;
  </code></pre>
  
  <p>and it should be:</p>
  
  <pre><code>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;td&gt;Id&lt;/td&gt;&lt;td&gt;Login&lt;/td&gt;...&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;row here&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
  </code></pre>
  
  <p>and i can't figure out what's missing. (btw. I'm using rails3)</p>
  
  <p>[EDIT]</p>
  
  <pre><code>def display_standard_table(columns, collection = {})    
    content_tag(:table) do
      concat(content_tag(:thead) do
        concat(content_tag(:tr) do
          concat(columns.collect { |column| content_tag(:td, column[:display_name]) })
        end)
      end)
  
      concat(content_tag(:tbody) do
        concat(collection.collect { |elem|
          content_tag(:tr, columns.collect { |column|
            content_tag(:td, elem.attributes[column[:name]])
          })
        })
      end)
    end
  end
  </code></pre>
  
  <p>The above version works ok but generated html is escaped :/ according to documentation strings produced by content_tag should be html_safe, but they're escaped :/</p>