Module: FoundationRailsHelper::FlashHelper

Defined in:
lib/foundation_rails_helper/flash_helper.rb

Constant Summary collapse

DEFAULT_KEY_MATCHING =

<div class=“callout [success alert secondary]” data-closable>

This is an alert box.
<button name="button" type="submit" class="close-button" data-close="">
  <span>&times;</span>
</button>

</div>

{
  alert:     :alert,
  notice:    :success,
  info:      :info,
  secondary: :secondary,
  success:   :success,
  error:     :alert,
  warning:   :warning,
  primary:   :primary
}.freeze

Instance Method Summary collapse

Instance Method Details

#display_flash_messages(closable: true, key_matching: {}) ⇒ Object

Displays the flash messages found in ActionDispatch’s flash hash using Foundation’s callout component.

Parameters:

  • closable - A boolean to determine whether the displayed flash messages

should be closable by the user. Defaults to true.

  • key_matching - A Hash of key/value pairs mapping flash keys to the

corresponding class to use for the callout box.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/foundation_rails_helper/flash_helper.rb', line 31

def display_flash_messages(closable: true, key_matching: {})
  key_matching = DEFAULT_KEY_MATCHING.merge(key_matching)
  key_matching.default = :primary

  capture do
    flash.each do |key, value|
      next if ignored_key?(key.to_sym)

      alert_class = key_matching[key.to_sym]
      concat alert_box(value, alert_class, closable)
    end
  end
end