I am working on an app that allows for a user to go to the root url like so:
http://localhost:3000/param_here
My Routes are setup like the following:
match '/:test' => redirect { |params| "/?id=#{params[:test]}" }
The problem with this is that my other routes are being picked up and being redirected as well.
Full Route.rb
Myapp::Application.routes.draw do
match '/:test' => redirect { |params| "/?id=#{params[:test]}" }
match '/aboutus', to: 'pages#aboutus', as: "about_us"
# Set the Home Page to a static page
root :to => 'pages#home'
end
So if a user goes to /aboutus, the redirect picks it up and assumes it should be set as the id. I still would like to use regular routes with also achieving this redirect
Have you tried moving the /aboutus route rule above the
rule in your routes file?
Routes flow from the top down so if you move your /about us route above the route with the optional params it should dispatch your request to the first matching route, in this case the /aboutus route