Module: Poodle::FlashHelper

Defined in:
app/helpers/poodle/flash_helper.rb

Instance Method Summary collapse

Instance Method Details

#flash_message(now = true) ⇒ Object

Example <div id=“div_flash_message”>

<%= flash_message() -%>

</div>



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/poodle/flash_helper.rb', line 34

def flash_message(now=true)
  message = get_flash_message(now)
  cls_name = "alert-info"
  cls_name = 'alert-success' if flash.now[:success] || flash[:success]
  cls_name = 'alert-warning' if flash.now[:alert] || flash[:alert]
  cls_name = 'alert-danger' if flash.now[:error] || flash[:error]

  message = message.strip if message

  (:div, class: "alert #{cls_name} fade in mb-10", "data-alert" => "alert") do
    raw(link_to("×", "#", class: "close", "data-dismiss" => "alert") + (:p, message))
  end unless message.blank?
end

#get_flash_message(now = true) ⇒ Object

Example ajax_notice = get_flash_message(true) notice = get_flash_message(false)



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

def get_flash_message(now=true)
  if now
    message = flash.now[:success] || flash.now[:notice] || flash.now[:alert] || flash.now[:error]
  else
    message = flash[:success] || flash[:notice] || flash[:alert] || flash[:error]
  end
  message
end

#set_flash_message(message, type, now = true) ⇒ Object

This function will set a flash message depending up on the request type (ajax - xml http or direct http) Example

set_flash_message("The message has been sent successfully", :success, false)
set_flash_message("Permission denied", :error)

Difference between flash and flash.now trace.adityalesmana.com/2010/10/difference-between-flash-and-flash-now-in-ruby/



10
11
12
13
14
15
16
# File 'app/helpers/poodle/flash_helper.rb', line 10

def set_flash_message(message, type, now=true)
  if now
    flash.now[type] = message
  else
    flash[type] = message
  end
end