活动资​​源参数序列化问题

时间:2013-02-25 12:05:42

标签: ruby-on-rails rest activeresource url-parameters query-parameters

我正在尝试将以下ruby哈希传递给活动资源(3.0.9)find(:from)调用。

my_hash = {
            :p => {:s => 100, :e => 2},
            :k => "blah",
            :f => [
                   {
                     :fl => :bt,
                     :tp => :trm,
                     :vl => "A::B"
                   },
                   {
                     :fl => :jcni,
                     :tp => :trm,
                     :vl => [133, 134]
                   },
                   {
                     :mnfl => :bmns,
                     :mxfl => :bmxs,
                     :tp => :rfstv,
                     :vl => 1e5
                   },
                   {
                     :fl => :bpo,
                     :tp => :rftv,
                     :op => :eta,
                     :vl => 1.months.ago.strftime("%Y-%m-%d")
                   }
                  ]
          }    

Resource.find_by_x_and_y(:all, :from => :blah, params: my_hash)

在服务器端操作,当我打印params散列时,它全部搞砸了。 (数组中的最后3个哈希映射到:f)

{
  "f" => [
          {
            "fl" => "bt",
            "tp" => "trm",
            "vl" => "A::B"
          },
          {
            "fl" => "jcni",
            "tp" => "trm",
            "vl" => [
                     "133",
                     "134"
                    ],
            "mnfl" => "bmns",
            "mxfl" => "bmxs"
          },
          {
            "tp" => "rfstv",
            "vl" => "100000.0",
            "fl" => "bpo",
            "op" => "eta"
          },
          {
            "tp" => "rftv",
            "vl" => "2013-01-25"
          }
         ],
  "k" => "blah",
  "p" => {
    "e" => "2",
    "s" => "100"
  },
  "action" => "blah",
  "controller" => "x/Y",
  "format" => "json"
}

my_hash.to_query给了我

f[][fl]=bt&f[][tp]=trm&f[][vl]=A%3A%3AB&f[][fl]=jcni&f[][tp]=trm&f[][vl][]=133&f[][vl][]=134&f[][mnfl]=bmns&f[][mxfl]=bmxs&f[][tp]=rfstv&f[][vl]=100000.0&f[][fl]=bpo&f[][op]=eta&f[][tp]=rftv&f[][vl]=2013-01-25&k=blah&p[e]=2&p[s]=100

没有索引,因此混淆。

使用“[]”是否有此类序列化的名称?这是否保证忠实地序列化/反序列化任意嵌套的哈希/数组/原语?如何使活动资源表现得非常好?

0 个答案:

没有答案