Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Tue Aug 19 22:14:04 -0700 2008 | [ajsharp] |
| |
README.textile | Thu Dec 04 09:16:52 -0800 2008 | [ajsharp] |
| |
Rakefile | Tue Aug 19 22:14:04 -0700 2008 | [ajsharp] |
| |
init.rb | Thu Dec 04 09:15:05 -0800 2008 | [ajsharp] |
| |
install.rb | Tue Aug 19 22:14:04 -0700 2008 | [ajsharp] |
| |
lib/ | Thu Dec 04 09:16:32 -0800 2008 | [ajsharp] |
| |
tasks/ | Tue Aug 19 22:14:04 -0700 2008 | [ajsharp] |
| |
test/ | Tue Aug 19 22:14:04 -0700 2008 | [ajsharp] |
| |
uninstall.rb | Tue Aug 19 22:14:04 -0700 2008 | [ajsharp] |
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
- MIT license
- ) 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:





