I have two sortable lists that you can drag and drop to and from. Each
object in the lists have a position field in the object's table. I
want to be able to update the position in the database automagically
once a user has sorted the list.
I can drag and drop just fine but I am not able to store the new
positions in the database.
I am trying to use Ajax.request in the onUpdate callback function. I
am not sure how to pass the order of the lists as parameters so that
the controller's action can update the position. Below is the related
code.
<script type="text/javascript" language="javascript">
// <![CDATA[
Sortable.create("left",
{dropOnEmpty:true,containment:["left","right"],constraint:false,
onUpdate:updateOrder});
Sortable.create("right",
{dropOnEmpty:true,containment:["left","right"],constraint:false,
onUpdate:updateOrder});
function updateOrder(){
var url = 'order' //the action
var left_list = escape(Sortable.sequence('left'));
var right_list = escape(Sortable.sequence('right'));
var left_ids = unescape(left_list).split(',');
var right_ids = unescape(right_list).split(',');
new Ajax.Request(url, {
method: 'post',
parameters: left_ids // how do I pass both left
and right ids and how do I use them in the action???
});
}
// ]]>
</script>
def order
//I need the new order so I can save it to the database
end
So, how do I pass the new order to the RoR action. Or is there a
better approach then what I am doing?
Please, please don't answer with php examples or simple alert type
examples.
Thanks, K
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---