def nested_comments(comments) ul(comments) do |item| member_thumb(User.find(item["user_id"])) + link_to(item["title"], :controller => 'communities', :action => 'show_topic', :id => item["id"]) + "The bottom version is more readable in a larger sense but top is way more concise. They use one of the available ruby concatenation methods." + item["content"] + "
" end end def nested_comments(comments) ul(comments) do |item| string = "" string << member_thumb(User.find(item["user_id"])) string << link_to(item["title"], :controller => 'communities', :action => 'show_topic', :id => item["id"]) string << "" string << item["content"] string << "
" string end end
View Helpers Make Strings
Posted by labrat
One thing you might come up against trying to make your view templates more readable and concise is stringing together a bunch of tags generated by link_to or some other method.
For example, I wanted to create nested comments with a thumbnail of the member profile, a link to the topic, and show the actual content. All the stuff generated by link_to and other helpers are ultimately spit out as strings. This will allow you to combine helpers by using the property of strings.
Here are two ways to create the same output:

Remember Object#returning!
returning “” do |str| str << member_thumb(…) #it’s ugly to call find from the views :-/ str << link_to(item[“title”], …) str << ” #{item[“content”]} ” end
http://weblog.jamisbuck.org/2006/10/27/mining-activesupport-object-returning