Skip to content

Commit 04315b0

Browse files
committed
Fix topics list fragment caching with I18n ruby-china#788
1 parent 5ef4fef commit 04315b0

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

app/views/home/index.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
<div class="home_suggest_topics panel panel-default">
44
<div class="panel-heading">社区精华帖</div>
55
<div class="panel-body topics row">
6+
<% cache(["home_suggest_topics", @excellent_topics]) do %>
67
<%
78
odd_topics, even_topics = @excellent_topics.partition.each_with_index { |t, i| i.odd? }
89
%>
910
<div class="col-md-6 topics-group">
10-
<%= render partial: "topics/topic", collection: odd_topics, locals: { suggest: false }, cached: -> (topic) { [topic, 'normal'] } %>
11+
<%= render partial: "topics/topic", collection: odd_topics, locals: { suggest: false } %>
1112
</div>
1213

1314
<div class="col-md-6 topics-group">
14-
<%= render partial: "topics/topic", collection: even_topics, locals: { suggest: false }, cached: -> (topic) { [topic, 'normal'] } %>
15+
<%= render partial: "topics/topic", collection: even_topics, locals: { suggest: false } %>
1516
</div>
17+
<% end %>
1618
</div>
1719
<div class="panel-footer">
1820
<%= link_to "查看更多精华帖...", excellent_topics_path %>

app/views/topics/_topic.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% cache([topic, suggest]) do %>
12
<div class="topic media topic-<%= topic.id %>">
23
<div class="avatar media-left">
34
<%= user_avatar_tag(topic.user, :md) %>
@@ -32,4 +33,5 @@
3233
<%= link_to(topic.replies_count,"#{topic_path(topic)}#reply#{topic.replies_count}", class: "state-false") %>
3334
<% end %>
3435
</div>
35-
</div>
36+
</div>
37+
<% end %>

app/views/topics/index.html.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
<div class="panel-body item-list">
1313
<% if @suggest_topics.present? %>
14-
<%= render partial: '/topics/topic', collection: @suggest_topics, locals: { suggest: true }, cached: -> (topic) { [topic, 'suggest'] } %>
14+
<%= cache(['topics', 'suggest', @topics]) do %>
15+
<%= render partial: '/topics/topic', collection: @suggest_topics, locals: { suggest: true } %>
16+
<% end %>
1517
<% end %>
1618

17-
<%= render partial: '/topics/topic', collection: @topics, locals: { suggest: false }, cached: -> (topic) { [topic, 'normal'] } %>
19+
<%= cache(['topics', 'normal', @topics]) do %>
20+
<%= render partial: '/topics/topic', collection: @topics, locals: { suggest: false } %>
21+
<% end %>
1822
</div>
1923

2024
<div class="panel-footer clearfix">

0 commit comments

Comments
 (0)