Sha256: 8d230f9c59730ff903a8145bfef2a128cae13f9a45aca617df3030eec6285f2e

Contents?: true

Size: 823 Bytes

Versions: 5

Compression:

Stored size: 823 Bytes

Contents

module BootstrapRailsHelpers::FlashHelper
  ALERT_TYPES = [:error, :info, :success, :warning]

  def alert_message(message, options = {})
    render :partial => 'bootstrap_rails_helpers/flash_alert', :locals => {
      :alert_type => options[:alert_type],
      :message => message
    }
  end

  def bootstrap_flash
    flash_messages = []
    flash.each do |type, message|
      # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
      next if message.blank?
    
      type = :success if type == :notice
      type = :error   if type == :alert
      next unless ALERT_TYPES.include?(type)

      Array(message).each do |msg|
        text = alert_message(msg, :alert_type => type)
        flash_messages << text if message
      end
    end
    flash_messages.join("\n").html_safe
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bootstrap-rails-helpers-0.0.6 app/helpers/bootstrap_rails_helpers/flash_helper.rb
bootstrap-rails-helpers-0.0.5 app/helpers/bootstrap_rails_helpers/flash_helper.rb
bootstrap-rails-helpers-0.0.4 app/helpers/bootstrap_rails_helpers/flash_helper.rb
bootstrap-rails-helpers-0.0.3 app/helpers/bootstrap_rails_helpers/flash_helper.rb
bootstrap-rails-helpers-0.0.2 app/helpers/bootstrap_rails_helpers/flash_helper.rb