GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A simple plugin to easy the sorting of html lists with the scriptaculous Sortable object.
Homepage: http://www.alexjsharp.com
Clone URL: git://github.com/ajsharp/list_sorter.git
name age message
file MIT-LICENSE Tue Aug 19 22:14:04 -0700 2008 initial commit [ajsharp]
file README.textile Thu Dec 04 09:16:52 -0800 2008 updated README [ajsharp]
file Rakefile Tue Aug 19 22:14:04 -0700 2008 initial commit [ajsharp]
file init.rb Thu Dec 04 09:15:05 -0800 2008 modified init.rb [ajsharp]
file install.rb Tue Aug 19 22:14:04 -0700 2008 initial commit [ajsharp]
directory lib/ Thu Dec 04 09:16:32 -0800 2008 major changes to list_sorter [ajsharp]
directory tasks/ Tue Aug 19 22:14:04 -0700 2008 initial commit [ajsharp]
directory test/ Tue Aug 19 22:14:04 -0700 2008 initial commit [ajsharp]
file uninstall.rb Tue Aug 19 22:14:04 -0700 2008 initial commit [ajsharp]
README.textile

ListSorter

This plugin is an adapted version of Recipe 5 of Chad Fowler’s Rails Recipes.

ListSorter provides a common interface to sort ActiveRecord models you’re representing via html lists (

    or
      ) in your view templates.

      There are two methods in the ListSorter module.

      collection_sort – This method sorts a collection of one AR object’s child models. I originally used it to sort a Product’s photos.

      Requirements

      1. Prototype + Scriptaculous 3. acts_as_list plugin (or possibly some derivative of this, though I haven’t tested any others so I can’t be sure)

      Example

      In your models:
      class Product < ActiveRecord::Base
          has_many :photos, :order => :position
      end
      
      class Photo < ActiveRecord::Base
          acts_as_list :scope => :product
      end
      

      In your controller:

      class ProductsController < ActionController::Base sort_list ‘bios’ end

      private
        def index
          bios = sortable_list
        end
      def sortable_list
        Products.all(:order => 'position')
      end

      In routes.rb:

      map.sort “products/sort/:id/:parent/:children”, :controller => ‘products’, :action => ‘sort’

      In your view:

      • MIT license