Module: FlashHelper

Defined in:
app/helpers/flash_helper.rb

Overview

This helper provides a method to include in the layout file in order to show an area presenting the flash messages sent by a controller. Note: Flash does refer to alert messages, not the vector graphics tool by adobe.

guides.rubyonrails.org/action_controller_overview.html#the-flash

Instance Method Summary collapse

Instance Method Details

#alert_field(type, message) ⇒ Object

Show a twitter bootstrap alert field. Possible types (bootstrap): info (blue), success (green), warning (yellow), danger (red) Possible types (rails): notice (-> info), alert (-> warning) Possible types (custom): error (-> danger)

getbootstrap.com/components/#alerts



22
23
24
25
26
27
28
# File 'app/helpers/flash_helper.rb', line 22

def alert_field(type, message)
  type = bootstrap_alert_type(type)
  # message = make_first_part_of_the_message_bold(message)
   :div, :class => "alert alert-#{type}" do
    close_button + message
  end.html_safe
end

#announcement_flashObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/flash_helper.rb', line 30

def announcement_flash
  announcement_file = File.join(Rails.root, "tmp", "announcement.md")
  if File.exist?(announcement_file)
    file_content = File.read(announcement_file)
    if file_content.present?
       :div, :class => 'alert alert-warning' do
        markup(file_content) 
      end
    end
  end
end

#flash_areaObject



9
10
11
12
13
# File 'app/helpers/flash_helper.rb', line 9

def flash_area
  flash.collect do |type, message|
    alert_field(type, message)
  end.join("\n").html_safe + announcement_flash
end