| 26 | | # Configuration options are: |
|---|
| | 14 | # Providing the capability to sort and reorder a models records. The model that will be sorted |
|---|
| | 15 | # should be referenced frm another model. |
|---|
| | 16 | # |
|---|
| | 17 | # ==== Options |
|---|
| | 18 | # * +column+ - specifies the column name to use for keeping the position integer (default: position) |
|---|
| | 19 | # * +scope+ - restricts what is to be considered part of the list. Typically this will be the name |
|---|
| | 20 | # of another model in lowercase as a symbol, acts_as_list will append "_id" onto the end (if it's not |
|---|
| | 21 | # there already) and use that to reference another model. It's also possible to give an entire SQL string |
|---|
| | 22 | # that is interpolated if you need a tighter scope than just a foreign key. |
|---|
| 28 | | # * +column+ - specifies the column name to use for keeping the position integer (default: position) |
|---|
| 29 | | # * +scope+ - restricts what is to be considered a list. Given a symbol, it'll attach "_id" |
|---|
| 30 | | # (if that hasn't been already) and use that as the foreign key restriction. It's also possible |
|---|
| 31 | | # to give it an entire string that is interpolated if you need a tighter scope than just a foreign key. |
|---|
| 32 | | # Example: <tt>acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt> |
|---|
| | 24 | # ==== Examples |
|---|
| | 25 | # |
|---|
| | 26 | # class TodoList < ActiveRecord::Base |
|---|
| | 27 | # has_many :todo_items, :order => "position" |
|---|
| | 28 | # end |
|---|
| | 29 | # |
|---|
| | 30 | # class TodoItem < ActiveRecord::Base |
|---|
| | 31 | # belongs_to :todo_list |
|---|
| | 32 | # acts_as_list :scope => :todo_list # this could also be todo_list_id |
|---|
| | 33 | # end |
|---|
| | 34 | # |
|---|
| | 35 | # # Gives you the following instance methods on the list model |
|---|
| | 36 | # todo_list.first.move_to_bottom |
|---|
| | 37 | # todo_list.last.move_higher |
|---|
| | 38 | # |
|---|
| | 39 | # Using the example from above and using an SQL query to reduce the scope to completed items only: |
|---|
| | 40 | # |
|---|
| | 41 | # class TodoItem < ActiveRecord::Base |
|---|
| | 42 | # belongs_to :todo_list |
|---|
| | 43 | # acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0' |
|---|
| | 44 | # end |
|---|