The flash hash is a great way to provide feedback to your users. Here is a quick tip for hiding the flash message after a period of time if you don’t want to leave it lingering around.
Next, add the following to either your layout (recommended), your view templates or a partial depending on your needs. I usually add this to a partial and include the partial in my layouts.
This will wrap the flash message in a div with
‘warn’ depending on the flash key specified.
‘10000’ is the time in milliseconds before the flash will disappear. In this case, 10 seconds.
As Mitchell has pointed out (see comments below), it may be better to set the
flash_type as the div class rather than its id. If there is the possibility that you’ll be showing more than one flash message per page, setting the flash_type as the div id will result in your HTML/XHTML code becoming invalid because the unique identifier will be used more than once per page.
Here is a slightly more complex version of the method shown above that will hide all divs with class “flash” after a time delay, achieving the same effect and also ensuring your code stays valid with more than one flash message!
In this example, the div id is not set at all. Instead, each flash div will have class “div” and also class of the type of flash message (“error”, “warning” etc.).