I am doing flash[:error] = "Hello World!" in my controller, and it shows properly in my view. However, flash[:error] is only deleted after the -second- time it is shown, which means that if I enter a wrong password, then navigate to the "lost password" page, I get a message saying "Invalid username or password" on -both- pages. What's the deal? AFAIK, Rails is supposed to delete the flash after it is rendered the first time.
People succeed in answering Carl's questions 23% of the time (5 successes in 22 attempts).
Answers by: Rich Collins | awt
You are probably doing the flash on the request that you show the error on. Flash stays on the session for the next request and is then deleted. You typically use flash for redirects where you set the flash, redirect and then show the message. Deletion of the flash has to do with the session and the subsequent request, not with the number of times it gets rendered.
So do you recommend setting @error instead of @flash[:error] instead?
(my developer is working on this stuff, not me)
Yes I would set an instance variable instead of a session (flash) variable.