Module: BootstrapFlashHelper

Defined in:
app/helpers/bootstrap_flash_helper.rb

Constant Summary collapse

ALERT_TYPES_MAP =
{
  notice: :success,
  alert: :danger,
  error: :danger,
  info: :info,
  warning: :warning
}.freeze

Instance Method Summary collapse

Instance Method Details

#bootstrap_flashObject



10
11
12
13
14
15
16
# File 'app/helpers/bootstrap_flash_helper.rb', line 10

def bootstrap_flash
  safe_join(flash.each_with_object([]) do |(type, message), messages|
              next if message.blank? || !message.respond_to?(:to_str)
              type = ALERT_TYPES_MAP.fetch(type.to_sym, type)
              messages << flash_container(type, message)
            end, "\n").presence
end

#flash_container(type, message) ⇒ Object



18
19
20
21
22
23
24
# File 'app/helpers/bootstrap_flash_helper.rb', line 18

def flash_container(type, message)
   :div, class: "alert alert-#{type} alert-dismissable" do
    button_tag type: "button", class: "close", data: { dismiss: "alert" } do
      "&times;".html_safe
    end.safe_concat(message)
  end
end