1

I fixed RoutingError in rails 3 using this link. I wanted 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

Adnan
  • 25,882
  • 18
  • 81
  • 110
Mateusz
  • 1,149
  • 1
  • 16
  • 33

1 Answers1

1

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

Community
  • 1
  • 1