I have some code like this:
<% cache "footer_links" do %>
<%= cms_snippet_content('footer_links') %>
<% end %>
And I thought of writing a helper method, like this one:
def cached_snippet_content(snip_id)
cache(snip_id) do
cms_snippet_content(snip_id)
end
end
However, I don’t get any output in my view, even though, my erb code looks like this:
<%= cached_snippet_content "footer_links" %>
What am I doing wrong?
May the source be with you, Luke:
This shows that
cacheis implemented to be called from ERB views, not from helpers. An alternative implementation:And now use it with the new Rails ERB style (<%= … > even in blocks if they output something):
I’d test this carefully, there may be hidden corners, I guess there’ll be a reason why
cachehas not been adapted to the Rails 3 block style.