30 Apr 2012

flash[:notice] not working? Check the obvious

I’ve just wasted twenty minutes debugging something that should have been obvious. For some reason a flash message was not showing in my rails app.

The html template that renders the flash is ok because it renders other messages. The code that sets the flash message in the controller seems right too. Then, why?

Flash messages are kept just for one request, after that, the flash hash is cleared. So the problem was that I was redirecting to the _rooturl and then automatically redirected again to the _loginurl because the user was not logged in. So the flash got lost in the second redirect. Obvious, right? That’s what I think.