Commit afaead97d8bd23eb00cded9dae25fdffa8dbc1af
1 parent
3aa7898c
Exists in
master
and in
23 other branches
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)
Showing
1 changed file
with
17 additions
and
15 deletions
Show diff stats
vendor/plugins/action_tracker_has_comments/init.rb
| 1 | # monkey patch to add comments on action_tracker | 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 | end | 22 | end |
| 20 | - root | ||
| 21 | - end | ||
| 22 | 23 | ||
| 24 | + end | ||
| 23 | end | 25 | end |