Sha256: 4825315bdd3f24fe05aaf1642a41d288dbf5a6bbf9632a0e480eda22c6e98fa1
Contents?: true
Size: 1.85 KB
Versions: 2
Compression:
Stored size: 1.85 KB
Contents
# EasyOrderable [](https://circleci.com/gh/sharoo/easy_orderable) Easy ordering of Active Record objects ## Usage ```ruby class User < ApplicationRecord include EasyOrderable has_many :bookings has_many :requests end class Booking < ApplicationRecord include EasyOrdearble belongs_to :user end class Request < ApplicationRecord include EasyOrderable belongs_to :renter, class_name: 'User', foreign_key: :user_id end #<User id: 1, first_name: 'A'> #<User id: 2, first_name: 'B'> #<User id: 3, first_name: 'C'> ``` ### Sort by column name asc ```ruby >> User.assort('first_name') => [#<User first_name: 'A'>, #<User first_name: 'B'>, #<User first_name: 'B'>] ``` ### Sort by column name desc ```ruby >> User.assort('-first_name') => [#<User first_name: 'C'>, #<User first_name: 'B'>, #<User first_name: 'A'>] ``` ### Sort by joined column name ```ruby >> Booking.assort('-user.first_name') ``` ### Sort by joined column name when associations name is custom ```ruby >> Request.assort('-user.first_name', user: :renter) ``` ### Sort by multiple params ```ruby >> Booking.assort('-user.first_name,slot_places') ``` ### You can use it from rails controller to handle json api compliant sort requests ```ruby class UsersController < ApplicationController def index @users = User.assort(order_param) end private def order_param params[:sort] end end ``` ## Installation Add this line to your application's Gemfile: ```ruby gem 'easy_orderable' ``` And then execute: ```bash $ bundle ``` Or install it yourself as: ```bash $ gem install easy_orderable ``` ## Contributing Contribution directions go here. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
easy_orderable-1.2.0 | README.md |
easy_orderable-1.1.1 | README.md |