Created
October 31, 2008 18:24
-
-
Save stympy/21378 to your computer and use it in GitHub Desktop.
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
<table> | |
<thead> | |
<tr><th>Name</th></tr> | |
</thead> | |
<tbody id="specifications"> | |
<% @specifications.each do |spec| %> | |
<tr id="spec-<%= spec.id %>"><td><%= spec.name %></td></tr> | |
<% end %> | |
</tbody> | |
</table> | |
<% content_for :head do -%> | |
<%= javascript_include_tag 'jquery.js', 'jquery.tablednd_0_5.js' %> | |
<script type="text/javascript" charset="utf-8"> | |
$().ready(function() { | |
$('#specifications').tableDnD({ | |
onDrop: function(table, row) { | |
$.ajax({ | |
type: "POST", | |
url: "<%= url_for(:action => 'sort') %>", | |
processData: false, | |
data: $.tableDnD.serialize() + '&authenticity_token=' + encodeURIComponent('<%= form_authenticity_token if protect_against_forgery? %>'), | |
success: function(msg) { | |
alert("The specifications have been updated") | |
} | |
}); | |
} | |
}) | |
}) | |
</script> | |
<% end -%> |
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
SpecificationsController < ActionController::Base | |
def sort | |
Specification.all.each do |spec| | |
if position = params[:specifications].index(spec.id.to_s) | |
spec.update_attribute(:position, position + 1) unless spec.position == position + 1 | |
end | |
end | |
render :nothing => true, :status => 200 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment