Enhances Rails with database-backed ordered sorting.


Keywords
sorting
License
Apache-2.0
Install
gem install sorter -v 0.22.0

Documentation

Sorter

🚫 This project is no longer maintained as of 2019-01-01. This project and all related versions will destroyed on 2020-01-01.

Enhances Rails with database-backed ordered sorting via controllers, models, and views.

Table of Contents

Features

  • Enables models to be sortable.
  • Adds view helpers and jQuery UI positioning controls with AJAX support.
  • Enables controllers to handle sortable resources (i.e. models) and respond to AJAX requests.
  • Provides JavaScript and CSS Rails Engine assets.

Requirements

  1. Ruby 2.6.x.
  2. Ruby on Rails 5.x.x.

Setup

Type the following to install:

gem install sorter

Add the following to your Gemfile file:

gem "sorter"

Add the following to your application.js file:

//= require jquery.sorter

Add the following to your application.css file:

*= require jquery.sorter

Usage

For models, add the following:

class Photo < ActiveRecord::Base
  sorter
end

This assumes the column used for storing position information is called "position". If this is not the case, you can change the defaults as follows:

class Photo < ActiveRecord::Base
  sorter column: :rank
end

For controllers, add the following:

class PhotosController < ApplicationController
  sorter
end

This assumes the resource (i.e. model) associated with this controller is call Photo. If this is not the case, you can change the defaults as follows:

class PhotosController < ApplicationController
  sorter model_class: RecordPhoto
end

The JavaScript code can be enabled via any .js file as follows:

$.sorter();

This will allow you to use the render_position_control helper method which will yield position controls (i.e. drag-n-drop, move to top, move up by one, move down by one, and move to bottom). All changes take place via AJAX calls back to your controller so that changes in your views are reflected back in the database.

Tests

To test, run:

bundle exec rake

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
  • Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright 2011 Alchemists. Read LICENSE for details.

History

Read CHANGES for details. Built with Gemsmith.

Credits

Developed by Brooke Kuhlmann at Alchemists.