Hi!
I defined function in application helper:
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
and I call it in my view:
<%= display_standard_table(
[
{ :name => 'id', :display_name => 'Id' },
{ :name => 'login', :display_name => 'Login' },
{ :name => 'first_name', :display_name => 'Name' },
{ :name => 'last_name', :display_name => 'LastName' },
{ :name => 'email', :display_name => 'Email'}
], @users) %>
The output in html is:
<table><thead></thead><tbody></tbody></table>
and it should be:
<table><thead><tr><td>Id</td><td>Login</td>...</tr></thead><tbody><tr>row here</tr></tbody></table>
and i can't figure out what's missing. (btw. I'm using rails3)
[EDIT]
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
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 :/