×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Ruby
Posted by: Massimo Zappino
Added: Dec 3, 2015 1:40 PM
Modified: Aug 27, 2017 3:32 PM
Views: 23
use

<%= flash_messages %>

in application.html.erb
  1. module ApplicationHelper
  2.  
  3.   def bootstrap_class_for flash_type
  4.     { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s
  5.   end
  6.  
  7.   def flash_messages(opts = {})
  8.     flash.each do |msg_type, message|
  9.       concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do
  10.               concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' })
  11.               concat message
  12.             end)
  13.     end
  14.     nil
  15.   end
  16. end