【发布时间】:2016-07-20 07:08:15
【问题描述】:
我的 rails4 应用程序中的帖子具有以下结构。用户可以对帖子发表评论,回复可以写在 cmets 上。我想在页面上使用带有自动过期键的 russian-doll-caching,但我不知道在这种情况下我应该怎么做。
sby 能告诉我在这种情况下如何使用它吗?
型号:
#post.rb
belongs_to :user
has_many :post_comments, dependent: :destroy
#post_comments.rb
belongs_to :user
belongs_to :post
has_many :post_comment_replies, dependent: :destroy
#post_comment_replies.rb
belongs_to :user
belongs_to :post_comments
posts/index.html.erb
<div class="post-index new-post-insert">
<%= render @posts %>
</div>
_post.html.erb
<%= post.body %>
<%= post.user.full_name %>
....
<%= render partial: 'posts/post_comments/post_comment', collection: post.post_comments.ordered.included, as: :post_comment, locals: {post: post} %>
_post_comment.html.erb
<%= post_comment.body %>
<%= post_comment.user.full_name %>
......
<%= render partial: 'posts/post_comment_replies/post_comment_reply', collection: post_comment.post_comment_replies.ordered.included, as: :post_comment_reply, locals: { post_comment: post_comment } %>
_post_comment_reply.html.erb
<%= post_comment_reply.user.full_name %>
<%= post_comment_reply.body %>
【问题讨论】:
-
这个 repo README 可以帮助github.com/rails/cache_digestslol
-
abookyun,我已经检查过了,但这是旧语法。我只是想确保我做的一切都很好。这是我第一次实现缓存,一堆文章已经过时了,就像这个 repo 一样。
标签: ruby-on-rails caching fragment-caching russian-doll-caching