Over a million developers have joined DZone.

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) }
      return flash[type].blank? ? "" : "


" end html end end

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}