Problem with returning values from a helper method in Rails
- by True Soft
I want to print some objects in a table having 2 rows per object, like this:
<tr class="title">
<td>Name</td><td>Price</td>
</tr>
<tr class="content">
<td>Content</td><td>123</td>
</tr>
I wrote a helper method in products_helper.rb, based on the answer of this question.
def write_products(products)
products.map {
|product|
content_tag :tr, :class => "title" do
content_tag :td do
link_to h(product.name), product, :title=>product.name
end
content_tag :td do
product.price
end
end
content_tag :tr, :class => "content" do
content_tag :td, h(product.content)
content_tag :td, product.count
end
}.join
end
But this does not work as expected. It only returns the last node - the last <td>123</td>
What should I do to make it work?