module ApplicationHelper

Methods added to this helper will be available to all templates in the application.

Public Instance Methods

flash_message(type, text) click to toggle source

A more robust flash method. Easier to add multiple messages of each type: :error, :success, :warning and :notice

# File app/helpers/application_helper.rb, line 6
def flash_message(type, text)
  available_types = [:error, :success, :warning, :notice]
  # If type isn't one of the four above, we display it as :notice.
  # We don't want to suppress the message, which is why we pick a
  # type, and :notice is the most neutral of the four
  type = :notice if !available_types.include?(type)
  # If a flash with that type doesn't exist, create a new array
  flash[type] = [] if !flash.key?(type)
  # If the message doesn't already exist, add it
  unless flash[type].include?(text)
flash_now(type, text) click to toggle source

A version of #flash_message using instead. This makes the flash available only for the current action.

# File app/helpers/application_helper.rb, line 22
def flash_now(type, text)
  available_types = [:error, :success, :warning, :notice]
  type = :notice if !available_types.include?(type)[type] = [] if[type].nil?