Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Rails Flash Messages Helper

DZone's Guide to

Rails Flash Messages Helper

·
Free Resource
in your view:

display_flash(:error) # to display a specific flash message
display_flash # to display all flash messages


# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  FLASH_TYPES = [:error, :warning, :success, :message]

  def display_flash(type = nil)
    html = ""
    
    if type.nil?
      FLASH_TYPES.each { |name| html << display_flash(name) }
    else
      return flash[type].blank? ? "" : "
  

#{flash[type]}

" end html end end
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}