Created
July 20, 2012 08:38
-
-
Save ozgun/3149646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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