Module: ShowMessage::ViewHelpers

Defined in:
lib/show_message/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#show_message(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/show_message/view_helpers.rb', line 4

def show_message(options = {})
  scope = options[:id].to_s

  if scope.present? && flash.keys.none? { |k| k.to_s.include?(scope) }
    return
  end

  data = []

  flash.each do |key, value|
    flash_type = key.to_s.split('_').first
    if key.is_a?(Array)
      value.each do |message|
        data.push(message: message, class: flash_type)
      end
    else
      data.push(message: value, class: flash_type)
    end
    flash.discard(key)
  end

  render partial: 'show_message/show_message', locals: {
    data: data, options: options
  }
end