Module: Handcart::BootstrapFlashHelper

Defined in:
app/helpers/handcart/bootstrap_flash_helper.rb

Constant Summary collapse

ALERT_TYPES =
[:danger, :info, :success, :warning]

Instance Method Summary collapse

Instance Method Details

#bootstrap_flashObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/handcart/bootstrap_flash_helper.rb', line 5

def bootstrap_flash
  flash_messages = []
  flash.each do |type, message|
    # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
    next if message.blank?

    type = type.to_sym
    type = :success if type == :notice
    type = :danger if type == :error
    next unless ALERT_TYPES.include?(type)

    Array(message).each do |msg|
      text = (:div,
                         (:button, raw("×"), class: "close", "data-dismiss" => "alert") +
                         msg.html_safe, class: "alert fade in alert-#{type}")
      flash_messages << text if msg
    end
  end
  flash_messages.join("\n").html_safe
end