How to extract URL parameters from a URL with Ruby or Rails?

Posted by Flackou on Stack Overflow See other posts from Stack Overflow or by Flackou
Published on 2010-03-23T14:00:12Z Indexed on 2010/03/23 14:03 UTC
Read the original article Hit count: 269

Filed under:
|
|
|

Hi,

I have some URLs, like http://www.example.com/something?param1=value1&param2=value2&param3=value3, and I would like to extract the parameters from these URLs and get them in a Hash. Obviously, I could use regular expressions, but I was just wondering if there was easier ways to do that with Ruby or Rails. I haven't found anything in the Ruby Module 'URI' but perhaps I missed something.

In fact, I need a method that would do that :

extract_parameters_from_url("http://www.example.com/something?param1=value1&param2=value2&param3=value3")
=> {:param1 => 'value1', :param2 => 'value2', :param3 => 'value3'}

Would you have some advices? Thanks in advance.

Julien

© Stack Overflow or respective owner

Related posts about rails

Related posts about ruby