Merge pull request #386 from AyuntamientoMadrid/include-tags

refactors debate's tags related utility methods
This commit is contained in:
Raimond Garcia
2015-09-06 22:55:31 +02:00
2 changed files with 5 additions and 3 deletions

View File

@@ -86,13 +86,15 @@ class Debate < ActiveRecord::Base
end end
def tag_list_with_limit(limit = nil) def tag_list_with_limit(limit = nil)
tags.most_used(limit).pluck :name return tags if limit.blank?
tags.sort{|a,b| b.taggings_count <=> a.taggings_count}[0, limit]
end end
def tags_count_out_of_limit(limit = nil) def tags_count_out_of_limit(limit = nil)
return 0 unless limit return 0 unless limit
count = tags.count - limit count = tags.size - limit
count < 0 ? 0 : count count < 0 ? 0 : count
end end

View File

@@ -3,7 +3,7 @@
<% if debate.tags.any? %> <% if debate.tags.any? %>
<span class='tags'> <span class='tags'>
<% debate.tag_list_with_limit(limit).each do |tag| %> <% debate.tag_list_with_limit(limit).each do |tag| %>
<%= link_to sanitize(tag), debates_path(tag: tag) %> <%= link_to sanitize(tag.name), debates_path(tag: tag.name) %>
<% end %> <% end %>
<% if debate.tags_count_out_of_limit(limit) > 0 %> <% if debate.tags_count_out_of_limit(limit) > 0 %>