Module: SimpleActsAsList::ModelAdditions::ClassMethods

Defined in:
lib/simple_acts_as_list/model_additions.rb

Instance Method Summary collapse

Instance Method Details

#simple_acts_as_list(opts = {}) ⇒ Object

Adds methods to consult informations about the list where the element belongs

:scope => Attribute that defines the list scope



23
24
25
26
# File 'lib/simple_acts_as_list/model_additions.rb', line 23

def simple_acts_as_list(opts={})
  cattr_accessor :simple_acts_as_list_scope_id
  self.simple_acts_as_list_scope_id = opts[:scope]
end

#simple_acts_as_list_scope(scope_id) ⇒ Object

Scope that returns item’s list ordered by position



29
30
31
32
33
# File 'lib/simple_acts_as_list/model_additions.rb', line 29

def simple_acts_as_list_scope(scope_id)
  self.where(
    "#{self.table_name}.#{self.simple_acts_as_list_scope_id}" => scope_id).
    order("#{self.table_name}.position")
end