app/views/admin/articles/position.html.haml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- form_tag update_position_admin_articles_path do
  .grid_5.alpha{:id => 'article-container'}
    %h3 Articles
    %ul#articles.connectedSortable
      - for article in @articles
        = content_tag(:li, article[0], :id => article[1], :class => 'ui-state-default')
  .grid_5.omega{:id => 'feature-container'}
    %h3 Featured Articles
    %ul#features.connectedSortable
      - for feature in @features
        = content_tag(:li, feature[0], :id => feature[1], :class => 'ui-state-highlight')
  = hidden_field_tag 'sort[articles]', ''
  = hidden_field_tag 'sort[features]', ''
  %br.clear
  = submit_tag "Update Position"

public/application.js

1
2
3
4
5
6
7
8
9
10
11
12
$(function() { 
  $("#articles, #features").sortable({ 
    connectWith: '.connectedSortable',
    update: function(element, ui) { 
        var result = $(this).sortable('toArray');
        var data = {};
        data[this.id] = result;
        document.getElementById('sort_' + this.id).value = result;
      }
    }) 
  });