0.0
No commit activity in last 3 years
No release in over 3 years
adds `next` and `previous` methods to your ActiveRecord instances
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.3
>= 0

Runtime

 Project Readme

NextRecord

Extends ActiveRecord by adding next and previous instance methods, returning the next and previous record according to a predefined order.

Installation

Add this line to your application's Gemfile:

gem 'next_record'

And then execute:

$ bundle

Or install it yourself as:

$ gem install next_record

Usage

Define an order in your model, using next_record_order. It takes the same arguments as ActiveRecord's order method:

class Person < ActiveRecord::Base
  next_record_order 'lower(trim(last_name))', :id
end

Find the previous and next records:

e = Person.first
e.next # => next record according to the defined order
e.previous # => previous record according to the defined order

TODO

  • Write tests... (so far it is tested in an app it is used in)