How to get normal view context when using ERB directly

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs