# Getting the "to be rendered" html w/o rendering it!

**URL:** <https://www.ruby-forum.com/t/getting-the-to-be-rendered-html-w-o-rendering-it/116051>\
**Category:** Rails\
**Created:** [October 1, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/getting-the-to-be-rendered-html-w-o-rendering-it/116051 "2007-10-01T22:36:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [October 1, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/getting-the-to-be-rendered-html-w-o-rendering-it/116051/1 "2007-10-01T22:36:11Z")

</div>

Hi all.

My code is in a controller

I want to be able to call “render” (or something else) to be able to get  
well formatted HTML from a very special :partial that I have. This HTML  
will not go to the user.

I will subsequently call “render” once for the page I want displayed to  
the user.

I believe I can accomplish this in a view by a call to render. However,  
I want/need to be able to do this in the controller.

Raw ERB does not seem like the right answer as I’d like to have access  
in the .rhtml file to all the stuff setup by the controller.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [October 1, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/getting-the-to-be-rendered-html-w-o-rendering-it/116051/2 "2007-10-01T22:39:44Z")

</div>

> I want/need to be able to do this in the controller.
> 
> Raw ERB does not seem like the right answer as I’d like to have access  
> in the .rhtml file to all the stuff setup by the controller.

render\_to\_string(options = nil, &block)

Renders according to the same rules as render, but returns the result in  
a  
string instead of sending it as the response body to the browser.
