# Stream content to template/layout

**URL:** <https://www.ruby-forum.com/t/stream-content-to-template-layout/177788>\
**Category:** Rails\
**Created:** [October 23, 2009, 6:29pm UTC](https://www.ruby-forum.com/t/stream-content-to-template-layout/177788 "2009-10-23T18:29:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjpatten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@pjpatten](https://www.ruby-forum.com/u/pjpatten)\
**Post date:** [October 23, 2009, 6:29pm UTC](https://www.ruby-forum.com/t/stream-content-to-template-layout/177788/1 "2009-10-23T18:29:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pjpatten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@pjpatten](https://www.ruby-forum.com/u/pjpatten)\
**Post date:** [October 23, 2009, 6:56pm UTC](https://www.ruby-forum.com/t/stream-content-to-template-layout/177788/2 "2009-10-23T18:56:22Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![pjpatten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@pjpatten](https://www.ruby-forum.com/u/pjpatten)\
**Post date:** [October 23, 2009, 7:58pm UTC](https://www.ruby-forum.com/t/stream-content-to-template-layout/177788/3 "2009-10-23T19:58:45Z")

</div>

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
