DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Standardizing Rails Flash Messages

02.03.2006
| 17720 views |
  • submit to reddit
        a proposal from Luke Randall on the rails mailing list

:notice for positive feedback (action successful, etc)
:message for neutral feedback (reminders, etc)
:warning for negative feedback (action unsuccessful, error encountered, etc)

Then, in your controller or view you could place code such as the following:

FLASH_NAMES = [:notice, :warning, :message]

<% for name in FLASH_NAMES %>
  <% if flash[name] %>
    <%= "<div id=\"#{name}\">#{flash[name]}</div>" %>
  <% end %>
<% end %>