# Rendering a partial without evaluating the erb tags

**URL:** <https://www.ruby-forum.com/t/rendering-a-partial-without-evaluating-the-erb-tags/168350>\
**Category:** Rails\
**Created:** [May 19, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/rendering-a-partial-without-evaluating-the-erb-tags/168350 "2009-05-19T21:45:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [May 19, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/rendering-a-partial-without-evaluating-the-erb-tags/168350/1 "2009-05-19T21:45:21Z")

</div>

Hi,  
I have a partial (\_contact.html) which looks something like this

I want to render this to the view exactly as it is show there. I don’t  
want the erb tags evaluating. When I try and render this using:  
render :partial =\> ‘contact.html’

I get an error because it is trying to evaluate the erb tags and call  
the name method on the non-existent contact object. I simply want to  
render the text, as it is written, to the view. How can I do this?

The reason for it is that I am investigating ways of JSON templating  
([John Resig - JavaScript Programming](http://ejohn.org/blog/javascript-micro-templating/)). I am ultimately  
aiming to make some of my partials reuseable between the rails code and  
the javascript code so that I only have to maintain them in one place.  
I want to carry on using \<%= %\> in the JSON templates. How can I tell  
rails just to render the partial as text and not try to evaluate it?  
Thanks

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [May 20, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/rendering-a-partial-without-evaluating-the-erb-tags/168350/2 "2009-05-20T14:43:57Z")

</div>

The only way I would think you can do it is by reading the template  
file into a variable in your controller and in your view escaping the  
string.

Not pretty.

Pepe

On May 19, 3:45 pm, Tim C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [May 20, 2009, 3:02pm UTC](https://www.ruby-forum.com/t/rendering-a-partial-without-evaluating-the-erb-tags/168350/3 "2009-05-20T15:02:47Z")

</div>

2009/5/20 pepe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> The only way I would think you can do it is by reading the template  
> file into a variable in your controller and in your view escaping the  
> string.
> 
> Not pretty.
> 
> Pepe

I think that having once read the template file into a variable in the  
controller it can be displayed without escaping in the view. The string  
will not be parsed as erb

Colin
