All the methods available to a record that has had acts_as_list specified. Each method works by assuming the object to be the item in the list, so chapter.move_lower would move that chapter lower in the list of all chapters. Likewise, chapter.first? would return true if that chapter is the first in the list of all chapters.
- decrement_position
- first?
- higher_item
- in_list?
- increment_position
- insert_at
- last?
- lower_item
- move_higher
- move_lower
- move_to_bottom
- move_to_top
- remove_from_list
Decrease the position of this item without adjusting the rest of the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 133 133: def decrement_position 134: return unless in_list? 135: update_attribute position_column, self.send(position_column).to_i - 1 136: end
Return true if this object is the first in the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 139 139: def first? 140: return false unless in_list? 141: self.send(position_column) == 1 142: end
Return the next higher item in the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 151 151: def higher_item 152: return nil unless in_list? 153: acts_as_list_class.find(:first, :conditions => 154: "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" 155: ) 156: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 166 166: def in_list? 167: !send(position_column).nil? 168: end
Increase the position of this item without adjusting the rest of the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 127 127: def increment_position 128: return unless in_list? 129: update_attribute position_column, self.send(position_column).to_i + 1 130: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 78 78: def insert_at(position = 1) 79: insert_at_position(position) 80: end
Return true if this object is the last in the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 145 145: def last? 146: return false unless in_list? 147: self.send(position_column) == bottom_position_in_list 148: end
Return the next lower item in the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 159 159: def lower_item 160: return nil unless in_list? 161: acts_as_list_class.find(:first, :conditions => 162: "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" 163: ) 164: end
Swap positions with the next higher item, if one exists.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 93 93: def move_higher 94: return unless higher_item 95: 96: acts_as_list_class.transaction do 97: higher_item.increment_position 98: decrement_position 99: end 100: end
Swap positions with the next lower item, if one exists.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 83 83: def move_lower 84: return unless lower_item 85: 86: acts_as_list_class.transaction do 87: lower_item.decrement_position 88: increment_position 89: end 90: end
Move to the bottom of the list. If the item is already in the list, the items below it have their position adjusted accordingly.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 104 104: def move_to_bottom 105: return unless in_list? 106: acts_as_list_class.transaction do 107: decrement_positions_on_lower_items 108: assume_bottom_position 109: end 110: end
Move to the top of the list. If the item is already in the list, the items above it have their position adjusted accordingly.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 114 114: def move_to_top 115: return unless in_list? 116: acts_as_list_class.transaction do 117: increment_positions_on_higher_items 118: assume_top_position 119: end 120: end
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 122 122: def remove_from_list 123: decrement_positions_on_lower_items if in_list? 124: end