Question

I'm trying to create a redirect for anyone that has parameters in a certain url, to the homepage. I currently have this in my routes:

match "/pr?campaign=#{'params[:campaign]'}" => redirect("/")

but it's not recognising it properly, if i put /pr?campaign=test into the url I get a page not found..

Was it helpful?

Solution

I'm not sure if I'm understanding your question, maybe try this:

match '/pr'           => 'controller#action'           # responds to no additional params
match '/pr/:campaign' => 'another_controller#action'   # responds to another param.

So, /pr will be received by controller#action, but /pr/test will be received by another_controller#action and receive test as params[:campaign]

Edit (actual solution to this problem):

match '/pr' => redirect('/')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top