Created
June 29, 2011 21:06
-
-
Save curtis/1054973 to your computer and use it in GitHub Desktop.
Mongoid sortable
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
$(document).ready(function() { | |
$('table.tracks tbody').makeSortable({ url: "<%= sort_my_mix_tracks_path(mix) -%>" }); | |
}); |
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
$.fn.makeSortable = function(options) { | |
$(this).sortable({ | |
axis: 'y', | |
dropOnEmpty:false, | |
handle: '.handle', | |
cursor: 'crosshair', | |
items: 'tr', | |
opacity: 0.4, | |
scroll: true, | |
update: function(){ | |
$.ajax({ | |
type: 'put', | |
data: $('table.tracks tbody').sortable('serialize'), | |
dataType: 'script', | |
url: options.url | |
}) | |
} | |
}); | |
} |
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
def sort | |
tracks = params[:track].collect { |id| mix.tracks.find(id) } | |
mix.tracks.clear | |
tracks.each { |t| mix.tracks.create(t.attributes) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment