Sha256: db2f3d3ab45b9a30b13375c70af8db654799d79bbc4fa86ba763083ffcead096

Contents?: true

Size: 1.06 KB

Versions: 41

Compression:

Stored size: 1.06 KB

Contents

module RailsDb
  module FlashMessagesHelper
    # <div class="alert-box [success alert secondary]">
    #   This is an alert box.
    #   <a href="" class="close">&times;</a>
    # </div>
    DEFAULT_KEY_MATCHING = {
      :alert     => :alert,
      :notice    => :success,
      :info      => :info,
      :secondary => :secondary,
      :success   => :success,
      :error     => :alert,
      :warning   => :warning
    }
    def display_flash_messages(key_matching = {})
      key_matching = DEFAULT_KEY_MATCHING.merge(key_matching)
      key_matching.default = :standard

      result = capture do
        flash.each do |key, value|
          alert_class = key_matching[key.to_sym]
          concat alert_box(value, alert_class)
        end
      end
      flash.clear
      result
    end

  private

    def alert_box(value, alert_class)
      content_tag :div, data: { alert: '' }, class: "alert-box #{alert_class}" do
        concat value
        concat close_link
      end
    end

    def close_link
      link_to("&times;".html_safe, '#', class: :close)
    end

  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
rails_db-2.4.4 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.4.3 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.4.2 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.4.1 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.4.0 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.3.1 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.3.0 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.2.1 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.2.0 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.1.1 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.1.0 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.0.6 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.0.5 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.0.4 app/helpers/rails_db/flash_messages_helper.rb
xplore-0.0.1.alpha app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.0.3 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.0.2 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.0.1 app/helpers/rails_db/flash_messages_helper.rb
rails_db-2.0.0 app/helpers/rails_db/flash_messages_helper.rb
rails_db-1.6.0 app/helpers/rails_db/flash_messages_helper.rb