I have a search form, with lot of options, Submitted to a route with Get request. URL is something like this:
http://localhost:3000/restaurants/search?utf8=%E2%9C%93&city=&cuisine=&number_of_people=&query=hello
with lot more params. I want to make it cleaner something like remove all the params which are blank.
something like this: (Basically removing all the params which are blank)
http://localhost:3000/restaurants/search?query=hello
How to do this?
One way can be using
CGI::parse("foo=bar&bar=foo&hello=hi")
Gives you
{"foo"=>["bar"], "hello"=>["hi"], "bar"=>["foo"]}
First redirect user on a in between action and in that in between action check which params are blank and remove them and then finally redirecting him on the actual action of search. But this sounds very lame thing. How can i do this in a better way?
query.gsub(/\w+=&/, '')
. – Explicate