2010-10-05 6 views
1

J'écris aide pour rendre la tête de table htmlComment rendre cette fonction html_safe?

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 

La sortie html est échappé:

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

Comment puis-je faire non échappés?

[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 

Répondre

2

concat? utilisez join sur le tableau mappé et voyez ce qui se passe.

+0

La jointure de thank a résolu le problème. Mais je n'arrive toujours pas à comprendre pourquoi concat gâcher les choses. Pouvez-vous m'éclairer? –

+0

En bref: non. Je n'ai jamais utilisé 'concat'. ;-) – Reactormonk

Questions connexes