加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 预构建片段缓存(内部方法)

发布时间:2020-12-16 21:03:40 所属栏目:百科 来源:网络整理
导读:我想预先构建一个需要几秒钟渲染的局部.我见过使用代理通过http预加载缓存的函数,但我希望有一个“内部”解决方案. 这是我的函数,每当myobject更新时都会调用它: def pre_build_partial myobject the_controller = ActionController::Base.new the_controll
我想预先构建一个需要几秒钟渲染的局部.我见过使用代理通过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

它适用于使用基本帮助程序的部分,但我的自定义助手会抛出错误:

未定义的方法`my_custom_helper_function’用于#<#< Class:...>

我想辅助器必须包含在the_controller中,但我找不到这样做的方法.在此先感谢您的帮助!

解决方法

你可以从源代码中选择一些想法:) https://github.com/rails/rails/issues/18409

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读