ruby-get-url-query-params

query params to hash and get params 

 

require 'uri'
irb(main):009:0* uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413") => #<URI::HTTP:0x007f95c7025e68 URL:http://foo.com/posts?id=30&limit=5#time=1305298413> irb(main):010:0> uri.host => "foo.com" irb(main):012:0> q = uri.query => "id=30&limit=5" irb(main):015:0> dds = URI.decode_www_form(q) => [["id", "30"], ["limit", "5"]] irb(main):018:0> Hash[dds] => {"id"=>"30", "limit"=>"5"} irb(main):019:0> h = Hash[dds] => {"id"=>"30", "limit"=>"5"} irb(main):020:0> h["id"] => "30"

 

posted on 2019-06-12 16:07  iokde.com  阅读(163)  评论(0编辑  收藏  举报

导航