Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do a redirection in routes.rb passing on the query string

I had a functioning redirect in my routes.rb like so;

match "/invoices" => redirect("/dashboard")

I now want to add a query string to this so that, e.g.,

/invoices?show=overdue

will be redirected to

/dashboard?show=overdue

I've tried several things. The closest I have got is;

match "/invoices?:string" => redirect("/dashboard?%{string}")

which gives me the correct output but with the original URL still displayed in the browser.

I'm sure I'm missing something pretty simple, but I can't see what.

like image 859
brad Avatar asked Dec 26 '12 10:12

brad


1 Answers

You can use request object in this case:

match "/invoices" => redirect{ |p, request| "/dashboard?#{request.query_string}" }
like image 100
mikdiet Avatar answered Nov 12 '22 16:11

mikdiet