Skip to content

Instantly share code, notes, and snippets.

@curtis
Created June 29, 2011 21:06
Show Gist options
  • Save curtis/1054973 to your computer and use it in GitHub Desktop.
Save curtis/1054973 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