From 19ef4819174be93fa6b2f8c72dd0173d47dbd211 Mon Sep 17 00:00:00 2001
From: David Gil
Date: Tue, 11 Aug 2015 18:43:53 +0200
Subject: [PATCH 01/11] adding counter_cache to comments children and WIPing on
the issue
---
app/models/comment.rb | 2 +-
app/views/comments/_comment.html.erb | 11 ++++++-----
app/views/debates/_debate.html.erb | 2 +-
app/views/debates/show.html.erb | 10 ++++++++--
app/views/welcome/_featured_debate.html.erb | 4 ++--
config/locales/en.yml | 17 +++++++++++++----
config/locales/es.yml | 19 +++++++++++++------
...11161459_add_children_count_to_comments.rb | 13 +++++++++++++
db/schema.rb | 5 +++--
spec/features/comments_spec.rb | 6 ++++++
10 files changed, 66 insertions(+), 23 deletions(-)
create mode 100644 db/migrate/20150811161459_add_children_count_to_comments.rb
diff --git a/app/models/comment.rb b/app/models/comment.rb
index d4ceb9e3e..913dd0780 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
diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb
index 4e375c540..9707c6462 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.debate.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") %>
- <%= t("debates.debate.responses", count: comment.children_count) %> + <%= t("debates.comment.responses", count: comment.children_count) %> <% if user_signed_in? %> | <%= render 'comments/form', {parent: comment, toggeable: true} %> diff --git a/app/views/comments/_votes.html.erb b/app/views/comments/_votes.html.erb index 4763388b3..73efa56ba 100644 --- a/app/views/comments/_votes.html.erb +++ b/app/views/comments/_votes.html.erb @@ -1,5 +1,6 @@ - númerototal votos + + <%= t('debates.comment.votes', count: comment.total_votes) %> | @@ -16,4 +17,4 @@ <% end %> <%= comment.get_dislikes.size %> - \ No newline at end of file + diff --git a/app/views/debates/_votes.html.erb b/app/views/debates/_votes.html.erb index a15a66a4d..4c252c8b5 100644 --- a/app/views/debates/_votes.html.erb +++ b/app/views/debates/_votes.html.erb @@ -18,7 +18,7 @@