Custom flash should be defined only for the class that defines it and it's subclasses

This fixes https://github.com/rails/rails/issues/12057