move tags helper to view, fix case when less than 5 tags were present, tag list was showing a + link
This commit is contained in:
@@ -1,17 +1,4 @@
|
||||
module ApplicationHelper
|
||||
|
||||
def tags(debate, limit = nil)
|
||||
tag_names = debate.tag_list_with_limit(limit)
|
||||
|
||||
tag_names.sort.map do |tag|
|
||||
link_to sanitize(tag), debates_path(tag: tag)
|
||||
end.join('').html_safe.tap do |output|
|
||||
if limit && extra_tags = debate.tags_count_out_of_limit(limit)
|
||||
output.concat(link_to("#{extra_tags}+", debate_path(debate)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def percentage(vote, debate)
|
||||
return "0%" if debate.total_votes == 0
|
||||
debate.send(vote).percent_of(debate.total_votes).to_s + "%"
|
||||
|
||||
@@ -47,8 +47,12 @@ class Debate < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def tags_count_out_of_limit(limit = nil)
|
||||
count = tags.count - limit
|
||||
count < 0 ? 0 : count
|
||||
if limit
|
||||
count = tags.count - limit
|
||||
count < 0 ? 0 : count
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<%- limit ||= nil %>
|
||||
|
||||
<% if debate.tags.any? %>
|
||||
<span class='tags'><%= tags(debate, limit) %></span>
|
||||
<span class='tags'>
|
||||
<% debate.tag_list_with_limit(limit).each do |tag| %>
|
||||
<%= link_to sanitize(tag), debates_path(tag: tag) %>
|
||||
<% end %>
|
||||
|
||||
<% if debate.tags_count_out_of_limit(limit) > 0 %>
|
||||
<%= link_to "#{debate.tags_count_out_of_limit(limit)}+", debate_path(debate) %>
|
||||
<% end %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user