Re: Sortable List, Serializing and Parsing with Ruby

OmenKing
Wed, 30 Jan 2008 18:25:09 -0000

Heres a pastie link if that helps:

http://pastie.caboo.se/145437

On Jan 30, 11:40 am, OmenKing
<omen.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> I have a sortable list that I serialize and pass to ruby to parse the
> results and update my array of hashes.
> eg.
>
> $tasks = [
>   { :id => 1, :name =>  ''Do the dishes'', :position
=> 3 },
>   { :id => 2, :name => ''Take out the trash'',
:position => 2 },
>   { :id => 3, :name => ''Shovel the driveway'',
:position => 1 }
> ]
>
> My hurdles:
>
> (1) serializing and passing with Ajax
>
> var list = Sortable.options(''tasks'').element;
> new Ajax.Request(''/tasks'', { parameters:
Sortable.serialize(list)});
>
> I get this:
>
> tasks%5B%5D=2&tasks%5B%5D=1&tasks%5B%5D=3
>
> would it be more useful if It was formating it as such?
> task{id}={position}&
>
> Where are the %5B%5D coming from?
>
> (2) parsing it in ruby
>
> I grab the request with web brick and I pass the query to params
>
> params = request.query
>
> How do I go about parsing it and updating my array of hashes?