The Rails flash
is present in the context of a request, and is managed internally using part of the session. So a method that references flash must be in that context, in other words a controller. Rails helpers are, by default, available in views only, not controllers. If you move your method to ApplicationController, then it should have access to the flash.
Here's the Rails documentation on flash