Module: EasyFlash

Defined in:
lib/easy_flash.rb,
lib/easy_flash/engine.rb,
lib/easy_flash/version.rb

Defined Under Namespace

Classes: Engine

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.empty_errorObject



88
89
90
# File 'lib/easy_flash.rb', line 88

def self.empty_error()
  flash[:error] = nil
end

.empty_messageObject



100
101
102
# File 'lib/easy_flash.rb', line 100

def self.empty_message()
  flash[:message] = nil
end

.empty_noticeObject



92
93
94
# File 'lib/easy_flash.rb', line 92

def self.empty_notice()
  flash[:notice] = nil
end

.empty_warningObject



96
97
98
# File 'lib/easy_flash.rb', line 96

def self.empty_warning()
  flash[:warning] = nil
end

.flash_helper(instance_variable = nil) ⇒ Object



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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/easy_flash.rb', line 10

def self.flash_helper(instance_variable = nil)

  Rails.logger.debug("------------- flash helper method from easy flash gem ---------------------")
  Rails.logger.debug(instance_variable.inspect)
  fl = ''

  if instance_variable && instance_variable.errors.any?
    fl += "<div class='error'>"
    fl += "<h2>#{pluralize(instance_variable.errors.count, "error")} prohibited this form from being submitted:</h2>"
    fl += "<ul>"
    instance_variable.errors.full_messages.each do |error|
      fl += "<li>#{error}</li>"
    end
    fl += "</ul></div>"
  else
    f_names = [:error, :notice, :warning, :message]

    for name in f_names
      unless flash[name].nil? || flash[name].empty?
        fl += "<div class='#{name}'><ul>"

        # if it is an array, print each element
        if flash[name].is_a?(Array)
          Rails.logger.debug("Yes, it is an array")
          flash[name].each do |message|
            fl += "<li>#{message}</li>"
          end
        else #if it is a single value, print that
          Rails.logger.debug(flash[name])
          fl += "<li>#{flash[name]}</li>"
        end

        fl += "</ul></div>"
      end
      flash[name] = nil
    end
  end

  fl = "<div class =\"custom_helper_flash\">" + fl + "</div>" unless fl.empty?

  fl.html_safe

  #rescue
  #  ""
end

.message?Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/easy_flash.rb', line 5

def self.message?
  Rails.logger.debug()
  puts "Flash Message Method!!"
end

.set_error(error) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/easy_flash.rb', line 56

def self.set_error(error)
  if flash[:error].nil?
    flash[:error] = error
  else
    flash[:error] << error
  end
end

.set_message(message) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/easy_flash.rb', line 80

def self.set_message(message)
  if flash[:message].nil?
    flash[:message] = message
  else
    flash[:message] << message
  end
end

.set_notice(notice) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/easy_flash.rb', line 64

def self.set_notice(notice)
  if flash[:notice].nil?
    flash[:notice] = notice
  else
    flash[:notice] << notice
  end
end

.set_warning(warning) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/easy_flash.rb', line 72

def self.set_warning(warning)
  if flash[:warning].nil?
    flash[:warning] = warning
  else
    flash[:warning] << warning
  end
end