Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scsmith/actsasadjacent

Simple rails plugin for adding the ability to get the next and previous activerecord objects. Scopes can also be defined as this makes use of named scopes under the hood. I'm not too sure this plugin is a good idea as its really just a couple of named scopes
https://github.com/scsmith/actsasadjacent

Last synced: 2 months ago
JSON representation

Simple rails plugin for adding the ability to get the next and previous activerecord objects. Scopes can also be defined as this makes use of named scopes under the hood. I'm not too sure this plugin is a good idea as its really just a couple of named scopes

Awesome Lists containing this project

README

        

ActsAsAdjacent
==============

Simple rails plugin for adding the ability to get the next and previous activerecord objects. Scopes can also be defined as this makes use of named scopes under the hood.

in item.rb
acts_as_adjacent

in controllers
@item = Item.find(5)
Item.next(5)
Item.previous(5)

You can also work directly on an instance
@item.next
@item.previous

This makes use of an offset relative to the record that is passed so it will work even if records are not sequential. So if records 1,2,4,5 are present 2.next will return 4

Copyright (c) 2009 Steve Smith, released under the MIT license