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
29
30
31
32
33
34
35
36
37
38
# File 'lib/show_message/view_helpers.rb', line 4

def show_message(options = {})

  scope = options[:id]

  if scope.present?
    flash_is_empty = false
    flash.keys.each do |k|
      puts k.to_s.index(scope.to_s).present?
      flash_is_empty = true unless k.to_s.index(scope.to_s).present?
    end
    return if flash_is_empty
  end


  data = []

  flash.each do |k, v|
    f = flash[k]
    if f.kind_of?(Array)
      if f
        f.each do |m|
          data << {message: m, class: k.to_s.split("_").first}
        end
      end
    else
      if f
        data << {message: v, class: k.to_s.split("_").first}
      end                                         
    end

    flash.discard(k) 
  end

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