# New Plugin released - records\_sequence

**URL:** <https://www.ruby-forum.com/t/new-plugin-released-records-sequence/140890>\
**Category:** Rails\
**Created:** [June 19, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/new-plugin-released-records-sequence/140890 "2008-06-19T14:52:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@aaron](https://www.ruby-forum.com/u/aaron)\
**Post date:** [June 19, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/new-plugin-released-records-sequence/140890/1 "2008-06-19T14:52:57Z")

</div>

I just finished a plugin called “records\_sequence” which add “next/  
previous” methods to each ActiveRecord object. After installed, it  
could be a pleasure to find a object’s neighbors.

== INSTALL ==

# This plugin requires Rails 2.1+ currently. Install it by below

command:  
ruby script/plugin install  
git://github.com/Aaron2Ti/records\_sequence.git

== USAGE ==

# After installed, your models could:

foo = User.first  
bar = foo.next  
bar2 = foo.previous  
foo\_neighbour = foo.previous # returns nil if foo has no previous  
neighbour

#The sequence’s sorted column is defined by the new  
option :sorted\_by,

# default is the ‘id’ column.

foo = User.last  
pre\_foo\_sorted\_by\_id = foo.previous  
pre\_foo\_sorted\_by\_age = foo.previous(:sorted\_by =\> ‘age’)

#Also works fine with most other ActiveRecord’s find options:  
foo = User.find 30  
foo.next(:conditions =\> [‘age \< ?’, 20])  
foo.previous(:offset =\> 2)  
foo.next(:sorted\_by =\> ‘address’, :order =\> ‘name DESC, age’)  
foo.previous( :sorted\_by =\> ‘age’, :conditions =\> [‘age \< ?’, 20],  
:order =\> ‘name DESC, address’, :offset =\> 2 )

Future info of this plugin also could be found at my blog:

> **[Plugin released - records\_sequence](http://aaron2ti.blogspot.com/2008/06/plugin-released-recordssequence.html)**
>
> In my last post , I wanted to have some flexible next or previous functions to find a object's neighbors. To fulfill that I just finished a ...
