Guest User

Untitled

a guest
Feb 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. # app/models/question.rb
  2. def new_position=(position)
  3. insert_at(position.to_i)
  4. end
  5.  
  6. # Make sure to add :new_position to permitted params in questions controller
  7.  
  8. # coffeescript
  9. $(document).on 'turbolinks:load', ->
  10. $('.sortable').sortable
  11. axis: 'y'
  12. handle: '.handle'
  13. update: (e, ui) ->
  14. data = new FormData
  15. data.append "question[new_position]", ui.item.index() + 1
  16. Rails.ajax
  17. url: "/questions/#{ui.item.data('question-id')}"
  18. type: "PATCH"
  19. data: data
Add Comment
Please, Sign In to add comment