acts_as_list

Module ActiveRecord::Acts::List::InstanceMethods
In:
vendor/rails/activerecord/lib/active_record/acts/list.rb
 
http://api.rubyonrails.org/classes/ActiveRecord/Acts/List/InstanceMethods.html#M000686
 

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.
 
 
 
Example

=======

  class TodoList < ActiveRecord::Base
    has_many :todo_items, :order => "position"
  end

  class TodoItem < ActiveRecord::Base
    belongs_to :todo_list
    acts_as_list :scope => :todo_list
  end

  todo_list.first.move_to_bottom
  todo_list.last.move_higher

Methods
  • 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

  • Public Instance methods
    decrement_position ()
    Decrease the position of this item without adjusting the rest of the list.
     
    first? ()
    Return true if this object is the first in the list.
     
    higher_item ()
    Return the next higher item in the list.
     
    in_list? ()
    Test if this record is in a list
     
    increment_position ()
    Increase the position of this item without adjusting the rest of the list.
     
    insert_at (position = 1)
    Insert the item at the given position (defaults to the top position of 1).
     
    last? ()
    Return true if this object is the last in the list.
     
    lower_item ()
    Return the next lower item in the list.
     
    move_higher ()
    Swap positions with the next higher item, if one exists.
     
    move_lower ()
    Swap positions with the next lower item, if one exists.
     
    move_to_bottom ()
    Move to the bottom of the list. If the item is already in the list, the items below it have their position adjusted accordingly.
     
    move_to_top ()
    Move to the top of the list. If the item is already in the list, the items above it have their position adjusted accordingly.
     
    remove_from_list ()
    Removes the item from the list.

    좋은 웹페이지 즐겨찾기