Skip to content

BigGreenCompany/order_by

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Order By

Adds order functionality to your ActiveRecord models so that your controllers have shared interface for accepting column/direction params.

Installation

Add this line to your application's Gemfile:

gem 'order_by'

And then execute:

$ bundle

Usage

Include Orderable concern to the model you want to act as orderable:

class Posts
  include Orderable
end

Now you can use it in your controller like this:

class PostsController
  def index
    @posts = Post.order_by(params[:sort_column], params[:sort_direction])
  end
end

Thanks

I was inspired by this gist and thought it would be useful as a gem

About

Adds order functionality to your ActiveRecord models so that your controllers have shared interface for accepting column/direction params

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages