From 6c9834f59a6aeab4313dc5177cd9c4ec3a77a8a8 Mon Sep 17 00:00:00 2001 From: PhilipDeFraties Date: Tue, 24 Dec 2024 10:49:24 -0700 Subject: [PATCH 1/4] move custom commontator classes to lib/classes directory --- {app/models/commontator => lib/classes}/comment.rb | 0 {app/models/commontator => lib/classes}/subscription.rb | 0 {app/models/commontator => lib/classes}/thread.rb | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {app/models/commontator => lib/classes}/comment.rb (100%) rename {app/models/commontator => lib/classes}/subscription.rb (100%) rename {app/models/commontator => lib/classes}/thread.rb (100%) diff --git a/app/models/commontator/comment.rb b/lib/classes/comment.rb similarity index 100% rename from app/models/commontator/comment.rb rename to lib/classes/comment.rb diff --git a/app/models/commontator/subscription.rb b/lib/classes/subscription.rb similarity index 100% rename from app/models/commontator/subscription.rb rename to lib/classes/subscription.rb diff --git a/app/models/commontator/thread.rb b/lib/classes/thread.rb similarity index 100% rename from app/models/commontator/thread.rb rename to lib/classes/thread.rb From d6eb54dc80e1c52df05955e5d07b176ef7d3a75e Mon Sep 17 00:00:00 2001 From: PhilipDeFraties Date: Tue, 24 Dec 2024 10:54:09 -0700 Subject: [PATCH 2/4] require commontator and acts_as_votable gems in custom comment class --- lib/classes/comment.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/classes/comment.rb b/lib/classes/comment.rb index b9626b4e5..444102424 100644 --- a/lib/classes/comment.rb +++ b/lib/classes/comment.rb @@ -1,3 +1,5 @@ +require "commontator" +require 'acts_as_votable' class Commontator::Comment < ActiveRecord::Base belongs_to :creator, polymorphic: true belongs_to :editor, polymorphic: true, optional: true From 97388dcc220481cb81e5b7e84455280e5ba99924 Mon Sep 17 00:00:00 2001 From: PhilipDeFraties Date: Tue, 24 Dec 2024 10:54:28 -0700 Subject: [PATCH 3/4] require commontator gem in subscription and thread classes --- lib/classes/subscription.rb | 1 + lib/classes/thread.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/classes/subscription.rb b/lib/classes/subscription.rb index 9860e5a08..7994bfe48 100644 --- a/lib/classes/subscription.rb +++ b/lib/classes/subscription.rb @@ -1,3 +1,4 @@ +require "commontator" module Commontator class Subscription < ActiveRecord::Base belongs_to :subscriber, :polymorphic => true diff --git a/lib/classes/thread.rb b/lib/classes/thread.rb index a3eb38fdb..93f0f657a 100644 --- a/lib/classes/thread.rb +++ b/lib/classes/thread.rb @@ -1,3 +1,4 @@ +require "commontator" class Commontator::Thread < ActiveRecord::Base belongs_to :closer, polymorphic: true, optional: true belongs_to :commontable, polymorphic: true, optional: true, inverse_of: :commontator_thread From 6abb779888112d94dd0b97151b7e3b04a2f770eb Mon Sep 17 00:00:00 2001 From: PhilipDeFraties Date: Tue, 24 Dec 2024 14:40:22 -0700 Subject: [PATCH 4/4] update syntax for preloader object initialization in Thread#nested_comments_for --- lib/classes/thread.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/classes/thread.rb b/lib/classes/thread.rb index 93f0f657a..6442598b0 100644 --- a/lib/classes/thread.rb +++ b/lib/classes/thread.rb @@ -153,8 +153,10 @@ def nested_comments_for(user, comments, show_all) ).tap do |nested_comments| next unless is_votable? - ActiveRecord::Associations::Preloader.new.preload( - nested_comments.flatten, :votes_for, ActsAsVotable::Vote.where(voter: user) + ActiveRecord::Associations::Preloader.new( + records: nested_comments.flatten, + associations: :votes_for, + scope: ActsAsVotable::Vote.where(voter: user) ) end end