# How to get normal view context when using ERB directly

**URL:** <https://www.ruby-forum.com/t/how-to-get-normal-view-context-when-using-erb-directly/136924>\
**Category:** Rails\
**Created:** [May 7, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/how-to-get-normal-view-context-when-using-erb-directly/136924 "2008-05-07T13:06:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@stefan](https://www.ruby-forum.com/u/stefan)\
**Post date:** [May 7, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/how-to-get-normal-view-context-when-using-erb-directly/136924/1 "2008-05-07T13:06:14Z")

</div>

Hi!

I’m creating a content management system and the standard rails layout/  
template/partial approach wasn’t going to cut it for me. I’m now  
rendering erb templates myself like so:

template = ERB.new(File.new("#{RAILS\_ROOT}/app/views/content/regular/  
#{self.class.to\_s.downcase}.html.erb").readline(nil))  
edit\_template.result(erb\_binding {template.result(erb\_binding {|  
symbol| yield\_content symbol} )})

The problem this presents is the unavailability of all the standard  
helper methods like for prototype and for creating tags. I can include  
all the helpers but I still get method missing errors:

include ActionView::Helpers::JavaScriptHelper  
include ActionView::Helpers::ScriptaculousHelper  
include ActionView::Helpers::PrototypeHelper  
include ActionView::Helpers::UrlHelper  
include ActionView::Helpers::TagHelper

gets me:

undefined method `protect\_against\_forgery?’ for #Section:0x19dad04

Is there any better way to get the full rails view rendering context  
when handling erb manually?

Regards,

Stefan

---

<div class="post-metadata">

**Author:** ![stefan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@stefan](https://www.ruby-forum.com/u/stefan)\
**Post date:** [May 7, 2008, 2:03pm UTC](https://www.ruby-forum.com/t/how-to-get-normal-view-context-when-using-erb-directly/136924/2 "2008-05-07T14:03:17Z")

</div>

Stefan wrote:

> Hi!
> 
> I’m creating a content management system and the standard rails layout/  
> template/partial approach wasn’t going to cut it for me. I’m now  
> rendering erb templates myself like so:

I cannot answer your specific question, but could elaborate a bit about  
why Rails’ approach isn’t good enough for your purpose? Maybe the answer  
lies a different way.

- Carsten
