Module: ActsAsImportant::ActMethod
- Defined in:
- lib/acts_as_important/acts_as_important.rb
Overview
:nodoc:
Instance Method Summary collapse
- #acts_as_important(options = {}) ⇒ Object
-
#concerned_with_importance ⇒ Object
Call this method from the user model.
Instance Method Details
#acts_as_important(options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/acts_as_important/acts_as_important.rb', line 3 def acts_as_important( = {}) has_many :importance_indicators, :as => :record, :dependent => :destroy has_many :active_importance_indicators, lambda { where :active => true }, :class_name => 'ImportanceIndicator', :as => :record, :dependent => :destroy has_many :concerned_users, :through => :active_importance_indicators, :source => :user # Left joins importance indicators from a particular user scope :with_user_importance, lambda{|user| joins("LEFT OUTER JOIN importance_indicators ON importance_indicators.record_id = #{quoted_table_name}.id AND importance_indicators.record_type = '#{name}' AND importance_indicators.user_id = #{user.id}")} scope :important_to, lambda{|user| joins(:importance_indicators).where("importance_indicators.user_id = #{user.id} AND importance_indicators.active = true")} scope :was_important_to, lambda{|user| joins(:importance_indicators).where("importance_indicators.user_id = #{user.id} AND importance_indicators.active = false")} scope :not_important_to, lambda{|user| with_user_importance(user).where("importance_indicators.record_id IS NULL")} scope :important_to_user_first, lambda{|user| with_user_importance(user).reorder('importance_indicators.record_id IS NOT NULL DESC')} extend ActsAsImportant::ClassMethods include ActsAsImportant::InstanceMethods end |
#concerned_with_importance ⇒ Object
Call this method from the user model
22 23 24 |
# File 'lib/acts_as_important/acts_as_important.rb', line 22 def concerned_with_importance has_many :importance_indicators end |