orderable
User customizeable ordering for active records.
How to use
Add a field to keep track of the ordering position to your model:
class AddOrderablePositionToPosition < ActiveRecord::Migration
def self.up
add_column :positions, :order_position, :integer
end
def self.down
remove_column :positions, :order_position
end
end
Include Orderable in your model
class Position < ActiveRecord::Base
include Orderable
Specify the column to use for ordering:
orderable_field_is :order_position
Now get the records back in order:
Position.in_order.all
Or update the ordering:
Position.update_order([0, 3, 2, 1])
Contributing to orderable
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
-
Fork the project
-
Start a feature/bugfix branch
-
Commit and push until you are happy with your contribution
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright © 2011 Darcy Laycock, John Barker. See LICENSE.txt for further details.