Provide DataMapper with a default sorting method
dm-sorting is a gem allowing you to define in a clear way the default criterium to sort your data.
Install
$ gem install dm-sorting
Example
require 'dm-core'
require 'dm-sorting'
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
property :age, Integer
sort_by :name.asc, :age.desc # default_order and order_by are available too
end
Written by Giovanni Capuano
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#