I'm trying do render a haml template that is outside of the normal rails
mvc. The problem I am having is that when I instantiate view none of the
_helper_methods from the controller are available to the view such as
'protect_against_forgery?, form_authenticity_token, etc'. I've looked
through the code and can't figure out how exactly rails includes these
methods in the view. Doing the following works but it seems hackish.
template = File.join("#{Rails.root}", 'lib', 'moustache_cms',
'templates')
context = ActionView::Base.new(template, {}, @controller, nil)
_controller = @controller
context.class_eval do
include Rails.application.routes.url_helpers
include Rails.application.routes.mounted_helpers
# hackish but can't seem to get helper_methods to working from views
otherwise.
_controller._helper_methods.each do |method_name|
define_method(method_name) { @controller.send(method_name) }
unless self.method_defined?(method_name)
end
end
context
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/qneoH9ivqukJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.