title: sorting UI for ranked-model gem
body: <p>I'm trying to make a sorting UI work with gem <code>ranked-model</code>.</p>
  
  <p>Gemfile:</p>
  
  <pre><code>gem 'ranked-model'
  gem 'jquery-ui-rails' #for drag-and-drop
  </code></pre>
  
  <p>application.js:</p>
  
  <pre><code>//= require jquery-ui/widgets/sortable
  </code></pre>
  
  <p>lesson.rb:</p>
  
  <p><code>class Lesson &lt; ApplicationRecord
    include RankedModel
    ranks :row_order
  end</code></p>
  
  <p>lessons_controller.rb - added sort function:</p>
  
  <pre><code>class LessonsController &lt; ApplicationController
    def index
      @lessons = Lesson.rank(:row_order)
    end
  
    def sort
      lesson = Lesson.find(params[:lesson_id])
      lesson.update(lesson_params)
      render body: nil
    end
  
    private
      def lesson_params
        params.require(:lesson).permit(:name, :row_order_position)
      end
  end
  </code></pre>
  
  <p>routes:</p>
  
  <pre><code>Rails.application.routes.draw do
    resources :lessons do
      put :sort
    end
  end
  </code></pre>
  
  <p>so that the routes look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/H8UVc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H8UVc.png" alt="routes"></a></p>
  
  <p>lessons.html.haml:</p>
  
  <pre><code>%h1 Lessons
  %table.table
    %thead
      %tr
        %th Name
    %tbody#item{"data-model_name": "lesson.class.name.underscore", "data-update_url": "lesson_sort_path(lesson)"}
      - @lessons.each do |lesson|
        %tr
          %td= lesson.name
  </code></pre>
  
  <p>table_sort.js:</p>
  
  <pre><code>$(function(){
    $('#item').sortable({
      update: function(e, ui){
        var item = ui.item;
        var item_data = item.data();
        var params = {_method: 'put'};
        params[item_data.modelName] = { row_order_position: item.index() }
        $.ajax({
          type: 'POST',
          url: item_data.updateUrl,
          dataType: 'json',
          data: params
        });
      }
    });
  });
  </code></pre>
  
  <p><strong>The sorting works, however it is not persisted and I get the following error in the logs. Any idea how to persist the sorting?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/N5C0h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N5C0h.png" alt="logs"></a></p>