有可能将params反转为原始的http请求

时间:2014-12-27 05:22:43

标签: ruby-on-rails ruby

我在控制器中打印参数

如何转换为原始http请求,例如

http://SERVER/queries?product_type="IF"..

{
            "market" => "cffex_hfts",
      "product_type" => "IF",
         "frequency" => "minute",
    "contract_month" => "2014-03-01 00:00:00",
          "start_at" => "2014-01-10 01:26:00",
            "end_at" => "2014-01-10 08:26:00",
        "controller" => "queries",
            "action" => "index"
}

1 个答案:

答案 0 :(得分:1)

params = {
        "market" => "cffex_hfts",
  "product_type" => "IF",
     "frequency" => "minute",
"contract_month" => "2014-03-01 00:00:00",
      "start_at" => "2014-01-10 01:26:00",
        "end_at" => "2014-01-10 08:26:00",
    "controller" => "queries",
        "action" => "index"
}

params.to_query
=> "action=index&contract_month=2014-03-01+00%3A00%3A00&controller=queries&end_at=2014-01-10+08%3A26%3A00&frequency=minute&market=cffex_hfts&product_type=IF&start_at=2014-01-10+01%3A26%3A00"

参考:http://apidock.com/rails/Hash/to_query