Skip to content

Instantly share code, notes, and snippets.

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', ->
axis: 'y'
handle: '.handle'
update: (e, ui) ->
data = new FormData
data.append "#{'param-key')}[position]", ui.item.index() + 1
type: "PATCH"
data: data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment