Hello,
I am trying to get a UI in a Rails application working where I have a
number of unordered lists being given sortable behaviour using
Scriptaculous Sortable.
Everything is working well except I’m having a little trouble with the
format passed to the server via Sortable.serialize.
I found the below post from Yehuda K. (from quite some time ago) that
helps illustrate my problem:
http://old.nabble.com/Sortable-serialize-td7024666s27240.html
What Yehuda is saying (and what I’m sure most familiar with
Scriptaculous Sortable.serialize know) is that you might have a bunch of
li elements with ids like:
item_2, item_4, item_1, item_3, etc.
Then Sortable.serialize does its thing and you end up with a string that
looks like:
item[]=2&item[]=4&item[]=1&item=3 etc.
Yehuda goes on to say that:
“Rails converts the serialized form into params[:item] =
[“2”,“4”,“1”,“3”…]; in other words, a usable array.”
Now if I look in my development.log I can see a similar looking string
coming through (via an AJAX POST) like so:
Parameters: {“action”=>“sort”,
“sort_order”=>“item[]=2&item[]=6&item[]=1”,
“some_other_key”=>“some_other_value”, “controller”=>“items”}
But this is the problem, rather than Rails parsing this string into a
usable array, as Yehuda suggests it should be doing, I’m getting:
“sort_order”=>“item[]=2&item[]=6&item[]=1”
sent to my controller method in the params hash.
So before I start manually parsing this “item[]=2&item[]=6&item[]=1”
string, can anyone give me some up to date information about how
Sortable.serialize should be used with Rails these days? I’m sure I’m
missing something simple. I’m using Rails 2.3.4.