Problem with returning values from a helper method in Rails
Posted
by True Soft
on Stack Overflow
See other posts from Stack Overflow
or by True Soft
Published on 2010-04-13T20:13:44Z
Indexed on
2010/04/13
20:43 UTC
Read the original article
Hit count: 291
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?
© Stack Overflow or respective owner