A Rails plugin that lets you declare Models as sortable by a specific attribute. eg sortable_by :price
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
LICENCE
README
init.rb

README

= Sortable By

by Matthias Hennemeyer <mhennemeyer@gmail.com>

== Introduction

Rails Plugin.
Make Collections of ActiveRecord Models sortable by a specified attribute.

== Usage

Just declare it inside the model: (Model should have a price attribute in this case)
    class Model < ActiveRecord::Base
      sortable_by :price
    end
    Use it by calling sort:
    @models = [
      Model.create(:price => 5),
      Model.create(:price => 1),
      Model.create(:price => 3),
      Model.create(:price => 12),
      Model.create(:price => 7)
    ].sort.map(&:price) 
    # => [1,3,5,7,12]

  
== INSTALL:

  $ ruby script/plugin install git://github.com/mhennemeyer/sortable-by.git


Copyright (c) 2008 Matthias Hennemeyer, released under the MIT license