Module: ActsAsImportant::ClassMethods
- Defined in:
- lib/acts_as_important/acts_as_important.rb
Instance Method Summary collapse
-
#cache_importance_for(records, user) ⇒ Object
Find all the importance_indicators of the records by the user in a single SQL query and cache them in the records for use in the view.
Instance Method Details
#cache_importance_for(records, user) ⇒ Object
Find all the importance_indicators of the records by the user in a single SQL query and cache them in the records for use in the view.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/acts_as_important/acts_as_important.rb', line 29 def cache_importance_for(records, user) importance_indicators = [] ImportanceIndicator.where(:record_type => name, :record_id => records.collect(&:id), :user_id => user.id).each do |importance_indicator| importance_indicators[importance_indicator.record_id] = importance_indicator end for record in records record.cached_importance = importance_indicators[record.id] || false end return importance_indicators end |