Skip to content
ITMammoth edited this page Apr 27, 2018 · 1 revision

RailsSortable supports multiple classes sorting.

Here is an example for you.

# models
class FirstItem < ActiveRecord::Base
  include RailsSortable::Model
  set_sortable :sort
end

class SecondItem < ActiveRecord::Base
  include RailsSortable::Model
  set_sortable :sort
end

# controller
class MultipleClassesController < ApplicationController
  # GET /multiple_classes
  def index
    @items = (FirstItem.all + SecondItem.all).sort_by(&:sort)
  end
end
<!-- index.html.erb -->
...
  <tbody class="sortable-multiple-classes">
    <% @items.each_with_sortable_id do |item, sortable_id| %>
      <tr id="<%= sortable_id %>">
        <td><%= item.title %></td>
        <td><%= item.sort %></td>
        <td><%= item.updated_at %></td>
      </tr>
    <% end %>
  </tbody>
...
// javascript
(function($) {
    $(".sortable-multiple-classes").railsSortable();
})(jQuery);
Clone this wiki locally