How to get a query string from a URL in Rails

前端 未结 4 1511
故里飘歌
故里飘歌 2020-11-28 23:15

Is there is a way to get the query string in a passed URL string in Rails?

I want to pass a URL string:

http://www.foo.com?id=4&empid=6
         


        
4条回答
  •  自闭症患者
    2020-11-28 23:51

    Rack::Utils.parse_nested_query("a=2") #=> {"a" => "2"}
    

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

    Parse query strings the way rails controllers do. Nested queries, typically via a form field name like this lil guy: name="awesome[beer][chips]" # => "?awesome%5Bbeer%5D%5Bchips%5D=cool", get 'sliced-and-diced' into an awesome hash: {"awesome"=>{"beer"=>{"chips"=>nil}}}

    http://rubydoc.info/github/rack/rack/master/Rack/Utils.parse_nested_query https://github.com/rack/rack/blob/master/lib/rack/utils.rb#L90

提交回复
热议问题