From: Ezra Zygmuntowicz Date: 2006-09-14T12:32:50+09:00 Subject: Re: eRB <%= On Sep 13, 2006, at 7:32 PM, Jacob Fugal wrote: > On 9/13/06, Ezra Zygmuntowicz wrote: >> On Sep 13, 2006, at 6:05 PM, Rob Sanheim wrote: >> > 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? >> >> <% _erbout << "hi" %> >> >> Its ugly but it works. > > You can of course also wrap it in a helper[1] method of your own as > well, to get rid of the ugly. For example: > > def echo(value) > _erbout << value.to_s > end > > then later in your template: > > <% echo "Hi!" %> > > Jacob Fugal > > [1] If you take "helper" there literally in the rails sense, you > probably want it in your application_helper.rb file; the same can > apply for any ERB usage using "helper" in a more general sense, > however. > Actually that doesn't work in a helper. You will get this error:" undefined local variable or method `_erbout' for #<#: 0x358b7a0> its because when you call _erbout it takes a second arg that defaults to binding. The binding and _erbout are not available within a helper method. -Ezra