I'm trying to render a rails form using HAML outside of the normal Rails
flow using the code below:

template = File.join("#{Rails.root}", 'lib', 'templates')
context = ActionView::Base.new(template, {}, @controller, nil)
context.class_eval do
include Rails.application.routes.url_helpers
inlcude Rails.application.routes.mounted_helpers
Haml::Engine.new(template, :attr_wrapper => '\').render(context, { :@page
=> @page })

The problem is I keep receiving the following error undefined method
`protect_against_forgery?' for #<ActionView::Base:0x007fcd05b52fa0>

For some reason the helper_methods defined in the controller are not being
set on the ActionView::Base instance and I'm not sure how to set them or
how Rails goes about doing it. I've looked through the source code but
don't see how it is wired together. That said if I manually add the methods
using class_eval then it all works the template renders correctly

def protect_against_forgery?

def form_authenticity_token

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/7akt9KHpIIkJ.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouprubyonrails-talk @
postedDec 3, '12 at 9:22p
activeDec 3, '12 at 9:22p

1 user in discussion

Amkirwan: 1 post



site design / logo © 2022 Grokbase