Module: SortableNestedSet::InstanceMethods

Defined in:
lib/acts_as_sortable_nested_set.rb

Instance Method Summary collapse

Instance Method Details

#move(parent, children) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/acts_as_sortable_nested_set.rb', line 40

def move(parent, children)
  if children.size == 1
    move_to_child_of(parent)
  else
    prev_sibling = nil

    for i in 0...children.size
      if children[i] == self.id
        prev_sibling ? move_to_right_of(prev_sibling) : move_to_left_of(children[i+1])
        break
      end

      prev_sibling = children[i]
    end
  end
end

#self_and_descendants_with_sns_itemsObject



36
37
38
# File 'lib/acts_as_sortable_nested_set.rb', line 36

def self_and_descendants_with_sns_items
  self_and_descendants.includes(self.class.sns_items_type).collect { |category| [category, category.sns_items] }.flatten
end