Search code examples
ruby-on-railsnested-sortable

Disable the hash-conversion for params


The nestedSortable Plugin sends this POST-Parameter (via serialize):

chapter[87]=null&element[377]=87&chapter[88]=87

It describes a tree of chapters and elements. The order of the items in the string is important!

  • Chapter 87
    • Element 377
    • Chapter 88

When I access the params in the controller, the ordered string is converted to a hash, so the order is lost:

{"chapter"=>{"87"=>"null", "88"=>"87"}, "element"=>{"377"=>"87"}}

Is it possible to disable the built in hash-conversion or do I have to alter the content of the POST, so that Rails can't convert it to a hash?


Solution

  • You can work directly with the request:

     request.body.string
    

    depending on your setup, try request.body.read since its basically an IO