Adds order functionality to your ActiveRecord models so that your controllers have shared interface for accepting column/direction params.
Add this line to your application's Gemfile:
gem 'order_by'
And then execute:
$ bundle
Include Orderable concern to the model you want to act as orderable:
class Posts
include Orderable
endNow you can use it in your controller like this:
class PostsController
def index
@posts = Post.order_by(params[:sort_column], params[:sort_direction])
end
endI was inspired by this gist and thought it would be useful as a gem