From: Jay Levitt Date: 2005-09-11T07:01:32+09:00 Subject: Re: RCR to modify #puts and #print inside ERB In article <49958C10-DAD0-4E7C-B9AB-44C6D314A637@refinery.com>, gavin@refinery.com says... > My personal mental model says that #puts is for outputting content > that is the desired output of your program (unlike #warn). An ERB > template is a parametrized program in its own right, and its output > is the resulting string. If you want debug output, use #warn. Agreed. I find it interesting that most of the responders to the thread aren't active in the Rails group; Rails is where this sort of thing *really* would be nice. I admit I used "puts-as-debug" the other day, but only because I was doing a quick-and-dirty test and it was the first way I figured out to get some Rails output into webrick. It's certainly not something I'd keep in the code for more than 10 minutes. And in Rails, where ERB owns the view, Gavin's examples don't strike me as controlled at all - you often end up jumping between ERB and HTML tags. Here's some code from the Agile Rails book that could look a lot nicer if the "puts" metaphor were available: <% for product in @products -%>

<%= h(product.title) %>

<%= product.description %> <%= fmt_dollars(product.price) %> <% end %> vs. <% for product in @products puts "

", h(product.title), "

", product.description, '', fmt_dollars(product.price), "" end %> -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that's because I don't have a http://www.jay.fm | full grasp of the situation. - Mark Adler