Module: FlashHelper

Defined in:
app/helpers/flash_helper.rb

Instance Method Summary collapse

Instance Method Details

#close_alert_btn(type = "alert") ⇒ Object

Generate the html for a close button on alerts and other modules



29
30
31
# File 'app/helpers/flash_helper.rb', line 29

def close_alert_btn type="alert"
   :button, "×".html_safe, :class => "close", :'data-dismiss' => type
end

#flash_helper(keys = [:notice, :alert, :error]) ⇒ Object

a robust method to display flash messages



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/flash_helper.rb', line 7

def flash_helper keys=[:notice, :alert, :error]
  # allow keys to be a symbol or an array of symbols
  keys = [keys] unless keys.kind_of? Array

  # Alias classes, mostly so that a notice can be a success, alert a notice, etc.
  classes = {
    notice: "alert-success",
    alert: "alert-notice",
    error: "alert-error"
  }

  # html from each message
  html = ''
  flash.each do |key, msg|
    css_class = classes[key] || key
    html = html + (:div, raw(msg + close_alert_btn), :class => "alert #{css_class}") if keys.index key
  end

  return ( :div, html.html_safe, id: "flash_helper").html_safe
end