Stream content to template/layout

Hi there,

I would like to integrate contents from a 3rd party content mangement
system into my rails app. The CMS has some web services which deliver
HTML that is ready to be displayed on the site, so no parsing or
processing is neccessary on the rails end.

Now, the amount of HTML can be quite large, so ideally I would like to
directly stream it to the client. I am able to stream text by using a
proc method like this:

output = proc { |response, output| output.write(“CMS example content”);
output.flush }
render :text => output

However, unfortunately this does not work with a layout:
render :layout => “application”, :text => output

This renders the layout, but then instead of evaluating the proc method,
it is just converted to a string. The actual output is the string
representation of the proc object, e.g #<proc:0xec12f3@d …

How can I stream contents to a template/layout?

Thanks
Patrick

it is just converted to a string. The actual output is the string
representation of the proc object, e.g #<proc:0xec12f3@d …

How can I stream contents to a template/layout?

I could be wrong, but I don’t think :text works with :layout. I
always thought :text meant just render the darn text and nothing else
thank you very much!

What about setting the output of ‘output’ to @output_from_cms and then
referencing that in your layout?

Hey Phil,

I could be wrong, but I don’t think :text works with :layout. I
always thought :text meant just render the darn text and nothing else
thank you very much!

“render :text => output”
does exactly that.

render :layout => “application”, :text => “some output”
actually renders the layout including “some output”

render :layout => “application”, :text => proc { … }
renders the layout, too but does not evaluate the proc method.

What about setting the output of ‘output’ to @output_from_cms and then
referencing that in your layout?
Yup, that works. However, since it is a large amount of data, I’d rather
not want to save it to memory first. Is there no way to stream text
including the template?

Thanks
Patrick