rails/rails — pull request #12088 by gmaliar (2013-08-30 13:12:15+00:00)
Title: Rails 4 Custom Flash Type Undefined After Error

A suggested fix to https://github.com/rails/rails/issues/12057

After an error is raised the custom flash methods are unavailable, it seems that they disappear from the scope of from where they were defined.

The class instance variable which holds the name of the custom flash types persists but it does not redefine the method upon a new request (perhaps exceptions clear out the scope of the dynamically inserted methods of a controller?).

The suggested fix checks whether the controller has the new method and if it doesn't it define_method it.

I was not able to reproduce the error in the integration test while imitating a route that raises an exception so I added a unit test.