开发者

Including helpers when rendering a template/partial by hand

开发者 https://www.devze.com 2023-01-10 00:58 出处:网络
I use the following code to render a template to a string that I can use later on: renderer = ActionView::Base.new(MyApp::Application.config.view_path)

I use the following code to render a template to a string that I can use later on:

renderer = ActionView::Base.new(MyApp::Application.config.view_path)
# INCLUDE HELPERS HERE
data = renderer.render(:partial => template, :locals => locals)

However, I wan开发者_如何学Pythont to be able to access some helpers (actually all). In rails 2.3 I was able to do this:

renderer.extend ApplicationController.master_helper_module

However, as of Rails 3, this no longer works. So, how do I make my helper methods available to use in my template?


You may want to look at abstract_controller/rendering.rb It looks like in rails 3 we should be able to do something like this:

renderer = ApplicationController.view_context_class.new(...)

And the module master_helper_module is now accessed by name _helpers, and it should be already included in view_context_class

0

精彩评论

暂无评论...
验证码 换一张
取 消