Skip to content

Instantly share code, notes, and snippets.

@juanpujol
Forked from curtis/make element sortable
Created June 9, 2012 13:23
Show Gist options
  • Save juanpujol/2900944 to your computer and use it in GitHub Desktop.
Save juanpujol/2900944 to your computer and use it in GitHub Desktop.
Mongoid sortable
$(document).ready(function() {
$('table.tracks tbody').makeSortable({ url: "<%= sort_my_mix_tracks_path(mix) -%>" });
});
$.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
})
}
});
}
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