ActsAsPositioned is a featherweight gem for keeping records organized by position. We wrote it because keeping slideshow slides organized in RailsAdmin and Typus was frustrating. Stuff should just go where you put it.
ActsAsPositioned borrows much from ActsAsList, but does less and is more useful in today's Rails 3 universe.
- You are using Rails 3.1 or higher.
Add this to your gemfile:
gem 'acts_as_positioned', :git => 'git://github.com/stager94/acts_as_positioned.git'
Run bundle install
.
Run rails generate position MODEL
The generator creates a migration to add a position column of type integer to the specified model.
Run rake db:migrate
Call acts_as_positioned
in your models.
class Slide < ActiveRecord::Base
# this is the good bit:
acts_as_positioned
# remember to order by position, either here or in your controllers.
default_scope order(:position)
end
If positions aren't unique -- suppose you're organizing 24 songs under 2 albums -- supply an :under
option.
class Song < ActiveRecord::Base
belongs_to :album
acts_as_positioned :under => :album
end
Write to [email protected].