No commit activity in last 3 years
No release in over 3 years
This 'acts_as' extension provides the capability for having previous next methods for object. Previous & next are based on a specified column (default is id).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

ActsAsPreviousNext

Build Status Code Climate Gem Version Dependency Status

Description

This acts_as extension provides the capability for having previous & next methods for an object. Previous & next are based on a specified column (default is id).

Install

  • Rails >= 3

    In your Gemfile

    gem 'acts_as_previous_next'

    Currently is tested on ruby 1.9.3 & 2.0.0 and mysql

Example

  class Post < ActiveRecord::Base
    acts_as_previous_next
    # acts_as_previous_next column: :id
    # or
    # acts_as_previous_next :id
  end

  post = Post.new
  post.next # => nil
  post.save
  post.next # => post
  post.previous # => post
  another_post = Post.new
  another_post.save
  another_post.next # => post
  another_post.previous # => post

Authorization support

Currently CanCan authorization is supported as option (false by default). If cancan authorization is enabled then current_ability must be passed to previous next methods. So the previous example with cancan:

  class Post < ActiveRecord::Base
    acts_as_previous_next with_cancan: true

    belongs_to :user
  end

And in your view:

  link_to 'Next', @post.next(current_ability)
  link_to 'Previous', @post.previous(current_ability)

License

acts_as_previous_next is released under the MIT License