0

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..

user1738017
  • 609
  • 2
  • 12
  • 29
  • assuming you want to route based on the query string take a look at http://stackoverflow.com/questions/4888263/setting-up-rails-routes-based-on-querystring – Doon Nov 28 '12 at 13:26

1 Answers1

0

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('/')
macool
  • 659
  • 6
  • 11
  • sorry i've explained it really badly, `/pr` isn't a page, it's just a link with some params, I want them to redirect to the home page straight away, surely i wouldn't need to involve controllers? – user1738017 Nov 28 '12 at 13:29
  • 1
    `match '/pr' => redirect('/')` will redirect `/pr` and `/pr?campaign=test` to `/` – macool Nov 28 '12 at 13:33
  • well.. that was much simpler than i thought! Thanks! – user1738017 Nov 28 '12 at 13:35