Skip to content

Instantly share code, notes, and snippets.

@mlitwiniuk
Created December 17, 2010 08:48
Show Gist options
  • Save mlitwiniuk/744672 to your computer and use it in GitHub Desktop.
Save mlitwiniuk/744672 to your computer and use it in GitHub Desktop.
def reorder
@menu_items = current_site.menu_items.by_position.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @menu_items }
end
end
def sort
@menu_items = current_site.menu_items.by_position.all
@menu_items.each do |mi|
mi.position = params['menu_item'].index(mi.id.to_s) + 1
mi.save
end
render :nothing => true
end
<% content_for :head do %>
<script type="text/javascript">
$(document).ready(function(){
$('#menu_items').sortable({
axis: 'y',
dropOnEmpty: false,
handle: '.handle',
cursor: 'crosshair',
items: 'li',
opacity: 0.4,
scroll: true,
update: function(){
$.ajax({
type: 'post',
data: $('#menu_items').sortable('serialize'),
dataType: 'script',
complete: function(request){
$('#menu_items li').effect('highlight');
},
url: '<%= sort_admin_menu_items_path %>'
});
}
});
});
</script>
<% end %>
<ul class="list" id="menu_items">
<% @menu_items.each do |menu_item| %>
<li id="menu_item_<%= menu_item.id %>">
<div class="left">
<%= image_tag "icons/handle.png", :class=>"handle" %>
</div>
<div class="item">
<p><%= menu_item.name %></p>
</div>
</li>
<% end %>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment