# How to get the rendered string without using render\_to\_strin

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-rendered-string-without-using-render-to-strin/112245>\
**Category:** Rails\
**Created:** [August 16, 2007, 7:42pm UTC](https://www.ruby-forum.com/t/how-to-get-the-rendered-string-without-using-render-to-strin/112245 "2007-08-16T19:42:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [August 16, 2007, 7:42pm UTC](https://www.ruby-forum.com/t/how-to-get-the-rendered-string-without-using-render-to-strin/112245/1 "2007-08-16T19:42:50Z")

</div>

Hi,

I have a few sample letters that needs to be sent out. As part of the  
specification the layout needs to be used and to be shown to legal and  
then  
mail those letters and log the full content in the database.

The strategy is to prepare full body before the email is actually sent  
out.

In order to get the body of the email I was using,

body\_of\_email = render\_to\_string(:action =\>  
‘email\_templates/letters\_to\_vendor’, :layout =\> false

It worked in some cases but now I am getting

Can only render or redirect once per action

Is there a way to get the output of the templates as a string after  
substitution without using render functionality. I am new to Ruby.

Thanks

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [August 17, 2007, 1:26am UTC](https://www.ruby-forum.com/t/how-to-get-the-rendered-string-without-using-render-to-strin/112245/2 "2007-08-17T01:26:38Z")

</div>

The render\_to\_string won’t cause that error. Furthermore, to render an  
action you should use, “render\_component\_to\_string”. You can also use  
“render” directly and multiple times in your rhtml template to avoid  
using \_to\_string  
If that doesn’t fix it. some things to check:

Your filters: make sure any filter that redirects or renders something  
returns false

The actions: any action you render must not allow a  
“redirect\_to”/“render” to occur more than ounce
