Problem returning a Proc
b.candler at pobox.com
b.candler at pobox.com
Tue Sep 11 15:53:37 EDT 2007
Ezra Zygmuntowicz writes:
> There is a helper method for this that sets all the proper headers and
> whatnot. Here is how to use it to do what your example does:
>
> def world
> res = "Hello world from #{$$} at #{Time.now}!\n"
> render_defered do
> sleep 5
> res
> end
> end
Thank you. It's "render_deferred", but when I change use that it works.
Perhaps this example should go into the README.
What I found surprising (and still do) is that a controller action can
return a String directly, but a Proc cannot. Therefore, what exactly is it
that a Proc is supposed to do to generate output, which a controller action
doesn't have to do?
Looking in abstract_controller.rb, I see:
@_body = case caught
when :filter_chain_completed
call_action(action)
when String
caught
when nil
filters_halted
when Symbol
send(caught)
when Proc
caught.call(self)
else
raise MerbControllerError, "The before filter chain is broken dude.
wtf?"
end
and this is also called from Controller#dispatch (via 'super')
So at first glance, it looks like caught.call(self) ought to take the return
value of the Proc and treat it just the same as a String returned directly
from the controller method. But I'm clearly not understanding the flow of
control, because that's not what's happening.
Regards,
Brian.
More information about the Merb-devel
mailing list