How to display Flash messages in Rails

Tagged flash, rails, erb, haml  Languages ruby

Place the following in your ERB view:

<% [:info, :error].each do |key| %>
  <% if flash[key] %>
  <div class="<%= key %>" id="flash">
    <%= flash[key] %>
  </div>
  <% end %>
<% end %>

or use the following if you prefer Haml:

- [:notice, :error, :success].each do |key|
  - unless flash[key].blank?
    %p{ :class => "flash #{key}" }= flash[key]