Home

Awesome

jsort

jsort does the javascript/jquery stuff for drag&drop sortable lists in your rails applications.

Usage

Model

Your model should have a 'position'-column of type integer.

Controller

def sort
   params[:ordered_items].each_with_index do |id,idx|
     m = MyModel.find(id)
     m.position = idx
     m.save
   end
   render :nothing => true
end

View (HAML; obviously, will work with html.erb too)

- jsort(@my_items,'ordered_items', sort_my_controller_path) do |item|
  = item.name
  = link_to "[Edit]", edit_my_item_path(item)

Parameters

jsort ITEMS, NAME, PATH, [OPTIONS]

This will display an ordered list which is sortable by drag and drop. The block passed to jsort will be used to format each line/item. If no block is given item.to_s will be used to display the items.

Installation

Contributing to jsort

Copyright

Copyright (c) 2011 Andi Altendorfer. See LICENSE.txt for further details.