Ruby: How to turn a hash into HTTP parameters?

后端 未结 14 1587
故里飘歌
故里飘歌 2020-12-07 06:46

That is pretty easy with a plain hash like

{:a => \"a\", :b => \"b\"} 

which would translate into

\"a=a&b=b\"
<         


        
14条回答
  •  遥遥无期
    2020-12-07 07:34

    The best approach it is to use Hash.to_params which is the one working fine with arrays.

    {a: 1, b: [1,2,3]}.to_param
    "a=1&b[]=1&b[]=2&b[]=3"
    

提交回复
热议问题