module StarlightHelpers::Flash

Public Instance Methods

display_flash(what, &code) click to toggle source
# File lib/starlight_helpers/flash.rb, line 25
            def display_flash(what, &code)
              type = what.to_sym
              # something like Devise has overwritten flash
              if flash[type].is_a?(String)
                flash[type] = [flash[type]]
              end

  if flash[type]
                result = flash[type].inject([]) do |res, msg|
                  res << (block_given? ? code.call(msg) : msg)
                end
              end

              # sometimes flash isn't cleared after action
                    # "Please create or set 'default_locale'" is shown
                    # multiple times
              # better clear flash, it was already shown anyway
              flash.delete(type)
              result ? result.join(" "): nil
end
flash_alert(message) click to toggle source
# File lib/starlight_helpers/flash.rb, line 7
def flash_alert(message)
        flash_something(:alert, message)
end
flash_notice(message) click to toggle source
# File lib/starlight_helpers/flash.rb, line 11
def flash_notice(message)
        flash_something(:notice, message)
end
flash_something(what, message) click to toggle source
# File lib/starlight_helpers/flash.rb, line 15
def flash_something(what, message)
        type = what.to_sym
        if flash[type].is_a?(String)
                flash[type] = [flash[type], message]
        else
                flash[type] ||= []
                flash[type] << message
        end
end