Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails sortable lists with jquery ui
# Make sure to add :position to permitted params in questions controller
# Sortable items need data-update-url and data-param-key attributes
# coffeescript
$(document).on 'turbolinks:load', ->
$('.sortable').sortable
axis: 'y'
handle: '.handle'
update: (e, ui) ->
data = new FormData
data.append "#{ui.item.data('param-key')}[position]", ui.item.index() + 1
Rails.ajax
url: ui.item.data('update-url')
type: "PATCH"
data: data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment