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.
- D
- F
- H
- I
- L
- M
- R
Decrease the position of this item without adjusting the rest of the list.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 137 def decrement_position return unless in_list? update_attribute position_column, self.send(position_column).to_i - 1 end
Return true if this object is the first in the list.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 143 def first? return false unless in_list? self.send(position_column) == 1 end
Return the next higher item in the list.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 155 def higher_item return nil unless in_list? acts_as_list_class.find(:first, :conditions => "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" ) end
Test if this record is in a list
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 171 def in_list? !send(position_column).nil? end
Increase the position of this item without adjusting the rest of the list.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 131 def increment_position return unless in_list? update_attribute position_column, self.send(position_column).to_i + 1 end
Insert the item at the given position (defaults to the top position of 1).
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 78 def insert_at(position = 1) insert_at_position(position) end
Return true if this object is the last in the list.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 149 def last? return false unless in_list? self.send(position_column) == bottom_position_in_list end
Return the next lower item in the list.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 163 def lower_item return nil unless in_list? acts_as_list_class.find(:first, :conditions => "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" ) end
Swap positions with the next higher item, if one exists.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 93 def move_higher return unless higher_item acts_as_list_class.transaction do higher_item.increment_position decrement_position end end
Swap positions with the next lower item, if one exists.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 83 def move_lower return unless lower_item acts_as_list_class.transaction do lower_item.decrement_position increment_position end 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.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 104 def move_to_bottom return unless in_list? acts_as_list_class.transaction do decrement_positions_on_lower_items assume_bottom_position end 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.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 114 def move_to_top return unless in_list? acts_as_list_class.transaction do increment_positions_on_higher_items assume_top_position end end
Removes the item from the list.
Source: show
# File rails/activerecord/lib/active_record/acts/list.rb, line 123 def remove_from_list if in_list? decrement_positions_on_lower_items update_attribute position_column, nil end end