我有一个预构建缓存页面的对象。我称之为:
str = ActionView::Base.new(Rails.configuration.paths['app/views'])
.render(partial: 'item_generator/item_with_modal',
locals: { item: @item, format: 'div',
create_external: @create_external,
view_file: @view_file })
我如何制作它以便包含ApplicationHelper以便可以调用助手?
我目前有类似的东西:
<%=raw ApplicationController.helpers.js_clean(item.detail) %>
但宁愿只有:
<%=raw js_clean(item.detail) %>
答案 0 :(得分:0)
使用extend
在ActionView::Base
实例中包含帮助程序:
str = ActionView::Base.new(Rails.configuration.paths['app/views']).tap do |v|
v.extend(ApplicationController.helpers)
end.render(
partial: 'item_generator/item_with_modal',
locals: {
item: @item,
format: 'div',
create_external: @create_external,
view_file: @view_file
}
)