Method: Cms::SectionNode#move_to

Defined in:
app/models/cms/section_node.rb

#move_to(section, position) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/cms/section_node.rb', line 57

def move_to(section, position)
  #logger.info "Moving Section Node ##{id} to Section ##{sec.id} Position #{pos}"
  transaction do
    if self.parent != section.node
      remove_from_list
      self.parent = section.node
      save
    end
    if position < 0
      position = 0
    else
      #This helps prevent the position from getting out of whack
      #If you pass in a really high number for position, 
      #this just corrects it to the right number
      node_count =Cms::SectionNode.count(:conditions => {:ancestry => ancestry})
      position = node_count if position > node_count
    end
    
    insert_at_position(position)
  end
end