Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozgun/3149646 to your computer and use it in GitHub Desktop.
Save ozgun/3149646 to your computer and use it in GitHub Desktop.
# http://www.broadcastingadam.com/2012/07/advanced_caching_part_2-using_strategies/
# Step 3: Caching Views Generated from Arrays
# missing "}"
class Post
def cache_key
Digest::MD5.hexdigest "#{maximum(:updated_at).try(:to_i)}-#{count}"
end
end
# missing "do"s after "cache" method calls
<% cache @posts do %>
<% @posts.each do |post| %>
<% cache post, 'main-listing' do %>
<p>
<%= link_to post.author, author_path(post.author) %>
<%= link_to post.title, post_path(post) %><br \>
<%= truncate post.body %>
<%= post.comments.count %><%= pluralize "comments", post.comments.count %>
</p>
<% end %>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment