我想预先构建一个需要几秒钟才能渲染的部分。我见过使用代理通过 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
它适用于使用基本助手的部分,但我的自定义助手抛出错误:
undefined method `my_custom_helper_function' for #<#<Class:...>
我想助手必须包含在 中the_controller
,但我找不到这样做的方法。提前感谢您的帮助!