diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index 1d1d24c3af..f97345ab46 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -112,7 +112,7 @@ def show .includes(:tag) .references(:term_data) .where('term_data.name = ?', params[:id]) - @length = notes.collect(&:uid).uniq.length || 0 + @length = Tag.contributor_count(params[:id]) || 0 respond_with(nodes) do |format| format.html { render 'tag/show' } @@ -322,7 +322,7 @@ def contributors .references(:term_data, :node_revisions) .where('term_data.name = ?', params[:id]) .order('node_revisions.timestamp DESC') - @users = @notes.collect(&:author).uniq + @users = Tag.contributors(@tagnames[0]) end # /contributors diff --git a/app/models/tag.rb b/app/models/tag.rb index b05433eedb..bc7c8a72dc 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -52,8 +52,9 @@ def belongs_to(current_user, nid) node_tag && node_tag.uid == current_user.uid || node_tag.node.uid == current_user.uid end - def self.contributor_count(tagname) + def self.contributors(tagname) tag = Tag.includes(:node).where(name: tagname).first + return [] if tag.nil? nodes = tag.node.includes(:revision, :comments,:answers).where(status: 1) uids = nodes.collect(&:uid) nodes.each do |n| @@ -62,6 +63,11 @@ def self.contributor_count(tagname) uids+=n.revision.collect(&:uid) end uids = uids.uniq + User.where(id: uids) + end + + def self.contributor_count(tagname) + uids = Tag.contributors(tagname) uids.length end diff --git a/app/views/tag/contributors.html.erb b/app/views/tag/contributors.html.erb index 1ac3bf83e8..cbc36dd546 100644 --- a/app/views/tag/contributors.html.erb +++ b/app/views/tag/contributors.html.erb @@ -68,7 +68,7 @@ <% end %> - <% if @notes.nil? || @notes.length == 0 %> + <% if @users.nil? || @users.length == 0 %>
<%= raw t('tag.contributors.no_contributors', :tag => params[:id]) %>:
<% else %><%= user.name %> | -<%= t('tag.contributors.notes') %> » | +<%= user.username %> | +<%= t('tag.contributors.notes') %> » |