I'm trying to figure out how to encode a Hash parameter to be able to decode it with php.
In php:
$params = array('key1' => 'value1','fields' => array( 'id' ),'filters' => array('date' => array ('conditional' => 'BETWEEN','values' => array('2013-01-20','2013-01-22'))));
$s = http_build_query( $params)
which give
key1=value1&fields%5B0%5D=id&filters%5Bdate%5D%5Bconditional%5D=BETWEEN&filters%5Bdate%5D%5Bvalues%5D%5B0%5D=2013-01-20&filters%5Bdate%5D%5Bvalues%5D%5B1%5D=2013-01-22php
In rails:
params = {"key1"=>"value1", "fields"=>["id"], "filters"=>[{"date"=>[{"conditional"=>"BETWEEN", "values"=>["2013-01-20", "2013-01-22"]}]}]}
params.to_param
which give
key1=value1%fields%5B%5D=id&filters%5B%5D%5Bdate%5D%5B%5D%5Bconditional%5D=BETWEEN&filters%5B%5D%5Bdate%5D%5B%5D%5Bvalues%5D%5B%5D=2013-01-20&filters%5B%5D%5Bdate%5D%5B%5D%5Bvalues%5D%5B%5D=2013-01-22
so if we decode %5B and %5D: in php:
key1=value1&fields[0]=id&filters[date][conditional]=BETWEEN&filters[date][values][0]=2013-01-20&filters[date][values][1]=2013-01-22php
with rails:
key1=value1&fields[]=id&filters[][date][][conditional]=BETWEEN&filters[][date][][values][]=2013-01-20&filters[][date][][values][]=2013-01-22
So as you see, encoded urls are not the same, and when I'm trying to decode the rails encoded url with php, I don't obtain the same structure.
from rails encoded url:
Array
(
[key1] => value1%fields[]=id
[filters] => Array
(
[0] => Array
(
[date] => Array
(
[0] => Array
(
[conditional] => BETWEEN
)
)
)
[1] => Array
(
[date] => Array
(
[0] => Array
(
[values] => Array
(
[0] => 2013-01-20
)
)
)
)
[2] => Array
(
[date] => Array
(
[0] => Array
(
[values] => Array
(
[0] => 2013-01-22
)
)
)
)
)
)
instead of : (from php encoded url)
Array
(
[key1] => value1
[fields] => Array
(
[0] => id
)
[filters] => Array
(
[date] => Array
(
[conditional] => BETWEEN
[values] => Array
(
[0] => 2013-01-20
[1] => 2013-01-22php
)
)
)
)
Anyone has an idea how I could encode a Hash (with arrays) to a query in Rails as php do ?