Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # app/models/question.rb
- def new_position=(position)
- insert_at(position.to_i)
- end
- # Make sure to add :new_position to permitted params in questions controller
- # coffeescript
- $(document).on 'turbolinks:load', ->
- $('.sortable').sortable
- axis: 'y'
- handle: '.handle'
- update: (e, ui) ->
- data = new FormData
- data.append "question[new_position]", ui.item.index() + 1
- Rails.ajax
- url: "/questions/#{ui.item.data('question-id')}"
- type: "PATCH"
- data: data
Add Comment
Please, Sign In to add comment