Commit 9a8f28d6 by tady

tag treeをcache

parent 0f92598d
...@@ -3,7 +3,9 @@ module PostsHelper ...@@ -3,7 +3,9 @@ module PostsHelper
# @param {ActiveRecord::Relation} node # @param {ActiveRecord::Relation} node
def h_display_tree(node) def h_display_tree(node)
_html = '<ul>' _html = '<ul>'
_html << %Q{<li><a href="#{ root_path(q: '#' + node.name) }">#{node.name} <span class="badge">#{node.post_tags.count}</span></a></li>} if node.posts.count > 0
_html << %Q{<li><a href="#{ root_path(q: '#' + node.name) }">#{node.name} <span class="badge">#{node.posts.count}</span></a></li>}
end
node.children.each do |_child| node.children.each do |_child|
_html << h_display_tree(_child) _html << h_display_tree(_child)
end end
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
<% end %> <% end %>
</div> </div>
<div class="list-group"> <% cache('tag-tree', :expires_in => 1.hour) do %>
<% Tag.roots.each do |root| %> <div class="list-group">
<%= h_display_tree(root) %> <% Tag.roots.each do |root| %>
<% end %> <%= h_display_tree(root) %>
</div> <% end %>
</div>
<% end %>
</div><!--/span--> </div><!--/span-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment