From afaead97d8bd23eb00cded9dae25fdffa8dbc1af Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Fri, 4 Oct 2013 13:50:58 -0300 Subject: [PATCH] Fixes ActionTracker crash on development mode --- vendor/plugins/action_tracker_has_comments/init.rb | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/vendor/plugins/action_tracker_has_comments/init.rb b/vendor/plugins/action_tracker_has_comments/init.rb index 778f0d8..07985db 100644 --- a/vendor/plugins/action_tracker_has_comments/init.rb +++ b/vendor/plugins/action_tracker_has_comments/init.rb @@ -1,23 +1,25 @@ # monkey patch to add comments on action_tracker -ActionTracker::Record.module_eval do +Rails.configuration.to_prepare do + ActionTracker::Record.module_eval do - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC', :counter_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments}' + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC', :counter_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments}' - def conditions_for_comments - type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) - "source_type = '#{type}' AND source_id = '#{id}'" - end + def conditions_for_comments + type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) + "source_type = '#{type}' AND source_id = '#{id}'" + end - def comments_as_thread - result = {} - root = [] - self.comments.each do |c| - c.replies = [] - result[c.id] ||= c - c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c + def comments_as_thread + result = {} + root = [] + self.comments.each do |c| + c.replies = [] + result[c.id] ||= c + c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c + end + root end - root - end + end end -- libgit2 0.21.2