Rai*_*ana 5 ruby-on-rails fragment-caching helpers prebuild
我想预先构建一个需要几秒钟渲染的局部.我见过使用代理通过http预加载缓存的函数,但我希望有一个"内部"解决方案.
这是我的函数,每当myobject更新时都会调用它:
def pre_build_partial myobject
the_controller = ActionController::Base.new
the_controller.instance_variable_set '@myobject', myobject
view_renderer = ActionView::Renderer.new the_controller.lookup_context
view_renderer.render the_controller.view_context, { partial: 'mypartial', layout: false }
end
Run Code Online (Sandbox Code Playgroud)
它适用于使用基本帮助程序的部分,但我的自定义助手会抛出错误:
undefined method `my_custom_helper_function' for #<#<Class:...>
我想帮助者必须加入the_controller,但我找不到办法.在此先感谢您的帮助!
| 归档时间: |
|
| 查看次数: |
173 次 |
| 最近记录: |