Parse a string as if it were a querystring in Ruby on Rails

前端 未结 5 402
终归单人心
终归单人心 2020-11-28 23:12

I have a string like this:

\"foo=bar&bar=foo&hello=hi\"

Does Ruby on Rails provide methods to parse this as if it is a querystring,

5条回答
  •  既然无缘
    2020-11-28 23:51

    The

    CGI::parse("foo=bar&bar=foo&hello=hi")
    

    Gives you

    {"foo"=>["bar"], "hello"=>["hi"], "bar"=>["foo"]}
    

提交回复
热议问题