Sha256: 43b36bc8103f90a679eb2aec63724fac65968bc3c5f80e1558fe2cdf4b211c62

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

= acts_as_list_with_sti_support


== Description

This +acts_as+ extension provides the capabilities for sorting and reordering a number of objects in a list.
The class that has this specified needs to have a +position+ column defined as an integer on the mapped 
database table.



== Usage

If you just want a global list, simply add acts_as_list to the model.

  class ListItem < ActiveRecord::Base
    acts_as_list
  end

  ListItem.first.move_to_bottom
  ListItem.last.move_higher
	
	
The plugin accepts two optional parameters.

+column+:: specifies the name of the column to use for the position (default: position)
+scope+:: specifies the scope within which lists are ordered (default: 1 = 1, i.e., a global list)

  class FunkyList < ActiveRecord::Base
    has_many :funky_list_items
  end
  
  class FunkyListItem < ActiveRecord::Base
    belongs_to   :funky_list
    acts_as_list :column => :pos, :scope => :funky_list
  end

The +scope+ option can be supplied as a symbol or as a lambda.  The generated scope condition
will differ depending on the value's Type and the schema of the associated table.

+scope => type_symbol+:: yields "type_id = '99'", if type_id is defined on the table
+scope => type_symbol+:: yields "type = '99'", if type_id is not defined on the table 
+scope => lambda { |instance| "type_id = '#{instance.type_id}'"}+:: yields "type_id = '99'"

If you use the plugin within a single table inheritance (STI) design, no extra configuration is needed
to cause the position values to be scoped by type.

  class Label < ActiveRecord::Base
    acts_as_list
  end
	
  class BillingFrequency < Label
  end



== License

Copyright (c) 2010 Coroutine LLC, released under the MIT license

The plugin is a modestly modified version of the rails acts_as_list plugin released under the
MIT license by David Heinemeier Hansson.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_list_with_sti_support-0.1.0 README.rdoc