Created
January 19, 2010 22:03
-
-
Save bcalloway/281355 to your computer and use it in GitHub Desktop.
Ajax sorting of page results using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('img#spinner').hide(); | |
// Sort products by size selected from dropdown | |
$('form select#size').change(function() { | |
$('img#spinner').show(); | |
var size = $("select#size").val(); | |
if ($.getUrlVar('keywords')) { | |
var keywords = $.getUrlVar('keywords'); | |
var url = "/products?size=" + size + "&keywords=" + keywords + " ul.product-listing"; | |
} else { | |
var url = "/products?size=" + size + " ul.product-listing"; | |
} | |
$('#products-list').load(url, function() {$('img#spinner').hide();}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductsController < ApplicationController | |
def index | |
if params[:size] == "asc" | |
@products = Product.ascend_by_master_width | |
elsif params[:size] == "desc" | |
@products = Product.descend_by_master_width | |
else | |
@products = Product.all | |
end | |
respond_to do |format| | |
index.html | |
index.js { render :partial => '/shared/products' } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment