ruby-on-rails

Rails: Converting URL strings to params?


I know Rails does this for you, but I have a need to do this myself for examples. Is there a simple, non-private method available that takes a string and returns the hash of params exactly as Rails does for controllers?


Solution

  • I found a way after a more intense Google search.

    To convert url string to params:

    hash = CGI::parse(some_string)
    

    And (as bonus) from hash back to url string:

    some_string = hash.to_query
    

    Thanks to: https://www.ruby-forum.com/topic/69428