Let's say that I have: a 'Survey' with many 'Questions' which has many 'Answers'
If I had a 'Survey' that had 2 instances of a 'Question', let's call them: 'Good Question' and 'Bad Question'
'Good Question' has 5 'Answers' and 'Bad Question' has 3 'Answers'
If 'Good Question' and 'Bad Question' were connected sortable lists with this jQuery-UI interaction. http://jqueryui.com/sortable/#connect-lists
I know how to display them as 2 sortable lists using the jQuery-UI and I can also drop an 'Answer' from a 'Bad Question' to a 'Good Question'. But how would I save their new sorted positions and their newly sorted association to another 'Question' back to a Rails database?
Railscasts has how to save position for a single sortable lists but not for lists that belong to different associated models. http://railscasts.com/episodes/147-sortable-lists-revised
I really appreciate the help here!
EDIT
I realized that I just need to POST to the Rails controller, an element id of the list that I dropped the 'Answer' into (i.e <ol class = "connectableSortable" id = "Good_Question"</ol>
)
This is the syntax for how the Railscast does a POST to the Rails Controller to pass an array of object_id's in the sortable order.
jQuery ->
$('#faqs').sortable(
axis: 'y'
update: ->
$.post($(this).data('update-url'), $(this).sortable('serialize'))
)
How would I update this POST to pass the list ID to it, so I can just update the 'Question' foreign key for the 'Answer' to the list 'ID' that it fell into?
This SO answer has a way to retrieve the list ID. Get the item/object where the element is dropped
So now, I really just need to know how to pass an extra parameter back to the rails controller. Any help?
master_array = arr1 + arr2
and give that to jQuery. For you to save their newly sorted positions is a whole other thing though. You're actually wanting to save the lists order with respect to Survey, not Question. Just draw it on a piece of paper, starting with Survey on the left, then Questions all the way to Answers on the right. Also, can a Question be used in more that one survey?