diff --git a/app/models/comment.rb b/app/models/comment.rb index d4ceb9e3e..696b363ce 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,5 @@ class Comment < ActiveRecord::Base - acts_as_nested_set scope: [:commentable_id, :commentable_type] + acts_as_nested_set scope: [:commentable_id, :commentable_type], counter_cache: :children_count acts_as_votable validates :body, presence: true @@ -28,4 +28,19 @@ class Comment < ActiveRecord::Base user end + def total_votes + votes_for.size + end + + # TODO: faking counter cache since there is a bug with acts_as_nested_set :counter_cache + # Remove when https://github.com/collectiveidea/awesome_nested_set/issues/294 is fixed + # and reset counters using + # > Comment.find_each { |comment| Comment.reset_counters(comment.id, :children) } + def children_count + children.count + end + + def descendants_count + descendants.count + end end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 4e375c540..466752044 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -14,11 +14,12 @@
- númerototal respuestas - <% if user_signed_in? %> - | - <%= render 'comments/form', {parent: comment, toggeable: true} %>
- <% end %> + <%= t("debates.comment.responses", count: comment.children_count) %> + <% if user_signed_in? %> + | + <%= render 'comments/form', {parent: comment, toggeable: true} %> + <% end %> +
<%= link_to debate.title, debate %>
- <%= link_to pluralize(debate.comment_threads.count, t("debates.debate.comment"), t("debates.debate.comments")), debate_path(debate, anchor: "comments") %> + <%= link_to t("debates.debate.comments", count: debate.comment_threads.count), debate_path(debate, anchor: "comments") %>
<%= t("debates.show.comments") %>
+<%= t("debates.show.comments_title") %>
<% if user_signed_in? %><%= link_to featured_debate.title, featured_debate %>
- <%= link_to pluralize(featured_debate.comment_threads.count, t("debates.show.comment"), t("debates.show.comments")), debate_path(featured_debate, anchor: "comments") %> + <%= link_to t("debates.show.comments", count: featured_debate.comment_threads.count), debate_path(featured_debate, anchor: "comments") %>