# Generating ERB directly from RoR code

**URL:** <https://www.ruby-forum.com/t/generating-erb-directly-from-ror-code/154674>\
**Category:** Rails\
**Created:** [December 2, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/generating-erb-directly-from-ror-code/154674 "2008-12-02T21:04:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [December 2, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/generating-erb-directly-from-ror-code/154674/1 "2008-12-02T21:04:24Z")

</div>

I have a situation where it would be useful to generate ERB directly  
from Rails code, rather than taking it from a file. Is this possible?  
If so, how would one go about it?

Thanks,  
Ken McDonald

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [December 2, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/generating-erb-directly-from-ror-code/154674/2 "2008-12-02T22:23:38Z")

</div>

On Dec 2, 8:03 pm, Kenneth McDonald [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have a situation where it would be useful to generate ERB directly  
> from Rails code, rather than taking it from a file. Is this possible?  
> If so, how would one go about it?

Well there’s render :inline if you’re in a controller or you can just  
use erb directly

greeting = world  
ERB.new(“hello \<%= greeting %\>”).result binding #=\> “hello world”

Fred
