leomao10 / sorted

Sorting large datasets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sorted

Sorted is a simple object that will take an sql order string and a url sort string to let you sort large datasets over many pages (using will_paginate or kaminari) without losing state.

<img src=“https://secure.travis-ci.org/mynameisrufus/sorted.png” />

Gemfile

gem 'sorted', '~> 0.4.3'

View

Generate a sorted link with the email attribute:

link_to_sorted "Email", :email

Works the same as the link_to method except a second argument for the sort attribute is needed.

Model

Using the sorted method with the optional default order argument:

@users = User.sorted(params[:sort], "email ASC").page(params[:page])

About

Sorting large datasets

License:MIT License