Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Fragment Cache for article show page

  • Loading branch information...
commit cc3a15ab2065051dac960e9058487d88ed3fdc99 1 parent e3f8886
Reyes Yang authored
19 app/views/articles/_article.html.haml
View
@@ -1,16 +1,7 @@
- cache article do
%article.article
- %header.clearfix
- %h3.article_title
- = link_to article.title, article_url(article)
- %span.created_at<
- = t 'post_at'
- = article.created_at.in_time_zone(+8.hours).strftime('%D %T')
- - if article.tags.any?
- .tags
- %span= t 'tags'
- %ul.unstyled
- = render partial: 'tags/tag', collection: article.tags
- %span.operation.admin
- = link_to t('edit'), edit_article_path(article)
- = link_to t('destroy'), article, data: { confirm: 'Are you sure?' }, :method => :delete
+ = render partial: 'article_header', object: article, as: :article
+ .article_content
+ ~ format_text @article.content
+
+
15 app/views/articles/_article_header.html.haml
View
@@ -0,0 +1,15 @@
+- cache [article, :header] do
+ %header.clearfix
+ %h3.article_title
+ = link_to article.title, article_url(article)
+ %span.created_at<
+ = t 'post_at'
+ = article.created_at.in_time_zone(+8.hours).strftime('%D %T')
+ - if article.tags.any?
+ .tags
+ %span= t 'tags'
+ %ul.unstyled
+ = render partial: 'tags/tag', collection: article.tags
+ %span.operation.admin
+ = link_to t('edit'), edit_article_path(article)
+ = link_to t('destroy'), article, data: { confirm: 'Are you sure?' }, :method => :delete
3  app/views/articles/_article_summary.html.haml
View
@@ -0,0 +1,3 @@
+- cache [article, :summary] do
+ %article.article
+ = render partial: 'article_header', object: article, as: :article
2  app/views/articles/index.html.haml
View
@@ -8,5 +8,5 @@
.top_operation= link_to t('new_article'), new_article_path
- if @articles
- = render @articles
+ = render partial: 'article_summary', collection: @articles, as: :article
= will_paginate @articles
21 app/views/articles/show.html.haml
View
@@ -1,21 +1,2 @@
-%article.article
- %header
- %h3.article_title= @article.title
- %span.created_at
- = t 'post_at'
- = @article.created_at.in_time_zone(+8.hours).strftime('%D %T')
- - if @article.tags.any?
- %span.tags
- = t 'tags'
- - @article.tags.each do |tag|
- = link_to tagging_path(tag) do
- %span.label #{tag.name}
- -if logged_in? && current_user.admin?
- %span.operation
- = link_to t('edit'), edit_article_path(@article)
- = link_to t('destroy'), @article, data: { confirm: 'Are you sure?' }, :method => :delete
-
- .article_content
- ~ format_text @article.content
-
+= render @article
= render :partial => 'layouts/disque'
Please sign in to comment.
Something went wrong with that request. Please try again.