I fixed RoutingError in rails 3 using this link. I wan开发者_StackOverflowted to redirect users to root page so I added:
match '*a', :to => 'homes#index'
to my routes.rb.
Question is: can I define flash[:error] message in this 'match' line to be displayed on target page?
Regards, Mateusz
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
精彩评论