Over a million developers have joined DZone.

Rails Flash Messages Helper

·
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:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}