This is similar to Redirect and raise flash message when catch-all in routes
But I did run into this problem and it was giving me an issue because I was using MATCH
and when I used GET
, the alert
wouldn't flash. Eventually I found a working solution using the thread above and applying GET
in another manner.
match '*path' => redirect{ |p, req| req.flash[:alert] = "The page you requested is not valid."; '/' }, via: [:get]
This is what I ultimately came up with, via: [:get]
being key to making everything work.
And remember to place such code at the end of your routes.rb