Module: Interage::FlashMessageHelper

Included in:
ApplicationHelper
Defined in:
lib/interage/flash_message_helper.rb

Constant Summary collapse

ALIAS_TYPES =
{ notice: 'success', alert: 'info', error: 'danger' }.freeze

Instance Method Summary collapse

Instance Method Details

#flash_messagesObject



7
8
9
10
11
12
13
# File 'lib/interage/flash_message_helper.rb', line 7

def flash_messages
  messages ||= flashes.map do |type, message|
    bootstrap_alert(handler_type(type), handler_message(message))
  end

  safe_join(messages || [])
end

#flashesObject



15
16
17
# File 'lib/interage/flash_message_helper.rb', line 15

def flashes
  flash.to_h.symbolize_keys
end

#handler_message(messages) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/interage/flash_message_helper.rb', line 23

def handler_message(messages)
  return messages unless messages.respond_to?(:map)

  errors =  :ul do
    messages.map do |message|
      concat (:li, message)
    end
  end

  safe_join [errors]
end

#handler_type(type) ⇒ Object



19
20
21
# File 'lib/interage/flash_message_helper.rb', line 19

def handler_type(type)
  ALIAS_TYPES[type] || type
end