Ezra Zygmuntowicz
9/14/2006 3:33:00 AM
On Sep 13, 2006, at 7:32 PM, Jacob Fugal wrote:
> On 9/13/06, Ezra Zygmuntowicz <ezmobius@gmail.com> 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 #<#<Class:0x358b7c8>:
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