【发布时间】:2013-07-09 08:15:09
【问题描述】:
我有一个助手可以为引擎中的常见组件生成复杂的 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 助手希望它会在 Erb 中包装一个 HTML 块,因此不会像我上面描述的那样工作。
有没有办法将#cache 用于辅助方法中的字符串片段?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2