Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Enhances Rails with database-backed ordered sorting.

branch: master
README.md

Overview

Gem Version Code Climate GPA Gemnasium Status Travis CI Status Coverage Status

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

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. Any of the following Ruby VMs:
  2. Ruby on Rails 4.x.x.

Setup

For a secure install, type the following from the command line (recommended):

gem cert --add <(curl -Ls http://www.redalchemist.com/gem-public.pem)
gem install sorter --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

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
  is_sortable
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
  is_sortable column: :rank
end

For controllers, add the following:

class PhotosController < ApplicationController
  is_sortable
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
  is_sortable 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.

Testing

To test, do the following:

  1. cd to the gem root.
  2. bundle install
  3. bundle exec rspec spec

Versioning

Read Semantic Versioning for details. Briefly, it means:

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

Contributions

Read CONTRIBUTING for details.

Credits

Developed by Brooke Kuhlmann at Red Alchemist

License

Copyright (c) 2011 Red Alchemist. Read the LICENSE for details.

History

Read the CHANGELOG for details. Built with Gemsmith.

Something went wrong with that request. Please try again.