Rails @flash deprecation mis-warning
Took me a while to figure this one out. Rails 1.2.3 has a bug in which a deprecation is misrepresented. It happens when you display the flash in a partial called ‘flash’.
The description might be a tad too abstract, but it’s really quite simple. In Rails, the flash is a space where you can put messages. Stuff like ‘logged in succesful’ or ‘password not found’.
These messages are stored in a variable called flash.
Secondly, some pieces of Rails are what is called deprecated. This means those pieces should not be used any more.
By coincidence, a deprecation warning is shown when you use the flash variable in a template (partial) called _flash.rhtml. This happens because of the way Rails is designed: it always tries to access instance variables named after the partial itself. Rails tries to access the instance variable @flash, because the partial filename is also called flash… so even though nobody is defining the instance variable, a deprecation warning is thrown.
It’s a lot harder to explain than it is to see happening in the code.
Bottom line: don’t name your template ‘_flash.rhtml’ to display the flash.
It’s a bug that will be fixed in the next version of Rails though.
No comments yet.