Commit afaead97d8bd23eb00cded9dae25fdffa8dbc1af

Authored by Larissa Reis
1 parent 3aa7898c

Fixes ActionTracker crash on development mode

  Loads action_tracker_has_comments plugin, that dynamically adds
  comments to ActionTracker::Record, before every request in development
  mode to avoid undefined method error.

(ActionItem2728)
vendor/plugins/action_tracker_has_comments/init.rb
1 1 # monkey patch to add comments on action_tracker
2 2  
3   -ActionTracker::Record.module_eval do
  3 +Rails.configuration.to_prepare do
  4 + ActionTracker::Record.module_eval do
4 5  
5   - 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}'
  6 + 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}'
6 7  
7   - def conditions_for_comments
8   - type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id])
9   - "source_type = '#{type}' AND source_id = '#{id}'"
10   - end
  8 + def conditions_for_comments
  9 + type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id])
  10 + "source_type = '#{type}' AND source_id = '#{id}'"
  11 + end
11 12  
12   - def comments_as_thread
13   - result = {}
14   - root = []
15   - self.comments.each do |c|
16   - c.replies = []
17   - result[c.id] ||= c
18   - c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c
  13 + def comments_as_thread
  14 + result = {}
  15 + root = []
  16 + self.comments.each do |c|
  17 + c.replies = []
  18 + result[c.id] ||= c
  19 + c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c
  20 + end
  21 + root
19 22 end
20   - root
21   - end
22 23  
  24 + end
23 25 end
... ...