On Sep 13, 2006, at 6:05 PM, Rob Sanheim wrote: > On 9/13/06, Jacob Fugal <lukfugl / gmail.com> wrote: >> On 9/13/06, Jason Roelofs <jameskilton / gmail.com> wrote: >> > <% puts "Can't see me" %> --> nothing >> > >> > <%= puts "Can't see me" %> --> Can't see me >> >> That's wrong. When rendering an ERB template, those two constructs >> would be essentially equivalent. The both do the same thing: print >> "Can't see me" to STDOUT and add nothing to the rendered output. >> >> Using puts inside ERB does not put things into the rendered output -- >> it's not equivalent to PHP's echo/print. You should never need to use >> puts or print within ERB (unless your intent is to print diagnostics >> out to STDOUT while the ERB is being rendered). >> >> <% %> and <%= %> both evaluate an expression. The difference is that >> <%= %> includes the result of the expression (cast to a string using >> to_s) in the rendered output. The result of the expression: >> >> puts "Can't see me" >> >> is nil, since puts always returns nil. nil.to_s is an empty >> string, so >> even with the <%= %> form, nothing is added to the rendered output. >> >> What you want to do instead is just leave off the puts: >> >> Nothing added: <% "Can't see me" %> >> But printed here: <%= "Can see me" %> >> >> Jacob Fugal >> >> > > One thing I've often wondered is how do you output from w/i a "non > output" block...ie in java scriptlets these are equivalent: > > <% out.println("hi") %> > <%= "hi" %> > > With ERB I've had some (admittedly rare) cases where this would be > useful. Is it possible? > > - rob <% _erbout << "hi" %> Its ugly but it works. -Ezra