Skip to content

Instantly share code, notes, and snippets.

@drogus
Created October 6, 2010 22:16
Show Gist options
  • Save drogus/614204 to your computer and use it in GitHub Desktop.
Save drogus/614204 to your computer and use it in GitHub Desktop.
class ArticlesPart < Parts::Base
def index
return if fragment_exist?([:articles_part, Article.last])
@articles = Articles.recent
render
end
end
class EventsPart < Parts::Base
def index
# this is lazy loaded, so no need to check fragment cache
@events = Event.limit(10)
end
end
<%= cache([:events_part, Event.last]) do %>
<ul>
<% @events.each do |event| %>
<li><%= link_to event.name, [event] %></li>
<% end %>
</ul>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment