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 138
138: def decrement_position
139: return unless in_list?
140: update_attribute position_column, self.send(position_column).to_i - 1
141: 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 144
144: def first?
145: return false unless in_list?
146: self.send(position_column) == 1
147: end
Return the next higher item in the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 156
156: def higher_item
157: return nil unless in_list?
158: acts_as_list_class.find(:first, :conditions =>
159: "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"
160: )
161: end
Test if this record is in a list
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 172
172: def in_list?
173: !send(position_column).nil?
174: 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 132
132: def increment_position
133: return unless in_list?
134: update_attribute position_column, self.send(position_column).to_i + 1
135: end
Insert the item at the given position (defaults to the top position of 1).
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 79
79: def insert_at(position = 1)
80: insert_at_position(position)
81: 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 150
150: def last?
151: return false unless in_list?
152: self.send(position_column) == bottom_position_in_list
153: end
Return the next lower item in the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 164
164: def lower_item
165: return nil unless in_list?
166: acts_as_list_class.find(:first, :conditions =>
167: "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"
168: )
169: end
Swap positions with the next higher item, if one exists.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 94
94: def move_higher
95: return unless higher_item
96:
97: acts_as_list_class.transaction do
98: higher_item.increment_position
99: decrement_position
100: end
101: end
Swap positions with the next lower item, if one exists.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 84
84: def move_lower
85: return unless lower_item
86:
87: acts_as_list_class.transaction do
88: lower_item.decrement_position
89: increment_position
90: end
91: 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 105
105: def move_to_bottom
106: return unless in_list?
107: acts_as_list_class.transaction do
108: decrement_positions_on_lower_items
109: assume_bottom_position
110: end
111: 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 115
115: def move_to_top
116: return unless in_list?
117: acts_as_list_class.transaction do
118: increment_positions_on_higher_items
119: assume_top_position
120: end
121: end
Removes the item from the list.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/acts/list.rb, line 124
124: def remove_from_list
125: if in_list?
126: decrement_positions_on_lower_items
127: update_attribute position_column, nil
128: end
129: end