0
我有一個幫助程序爲引擎中的常見組件生成複雜的HTML。有沒有辦法在輔助方法中緩存字符串片段?
助手(很簡單):
def component(name)
component = Component.find_by_name!(name)
# a whole lot of complex stuff that uses component to build some HTML
end
查看:
<%= component(:my_component) %>
我要實現對這些組件片段緩存,但我想這樣做內#component
本身讓事情變得乾燥,例如
def component(name)
...
cache some_unique_fragment_name do
html
end
# or, more succinctly:
cache(some_unique_fragment_name, html)
end
的問題是Rails的cache助手預計,這將HTML包裹在厄爾布塊,所以正如我以上描述將無法正常工作。
有沒有辦法在助手方法中使用#cache
作爲字符串片段?