Sha256: 82183871d15d41cd7a6b320f723ed0d7ec0e8011c83f806330c7a56b877607c6

Contents?: true

Size: 1.64 KB

Versions: 20

Compression:

Stored size: 1.64 KB

Contents

module Poodle
  module FlashHelper
    # 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
    # http://trace.adityalesmana.com/2010/10/difference-between-flash-and-flash-now-in-ruby/
    def set_flash_message(message, type, now=true)
      if now
        flash.now[type] = message
      else
        flash[type] = message
      end
    end

    # Example
    # ajax_notice = get_flash_message(true)
    # notice = get_flash_message(false)
    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

    # Example
    # <div id="div_flash_message">
    #   <%= flash_message() -%>
    # </div>
    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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
poodle-rb-0.2.5 app/helpers/poodle/flash_helper.rb
poodle-rb-0.2.4 app/helpers/poodle/flash_helper.rb
poodle-rb-0.2.3 app/helpers/poodle/flash_helper.rb
poodle-rb-0.2.2 app/helpers/poodle/flash_helper.rb
poodle-rb-0.2.1 app/helpers/poodle/flash_helper.rb
poodle-rb-0.2.0 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.9 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.8 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.7 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.6 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.5 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.4 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.3 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.2 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.1 app/helpers/poodle/flash_helper.rb
poodle-rb-0.1.0 app/helpers/poodle/flash_helper.rb
poodle-rb-0.0.9 app/helpers/poodle/flash_helper.rb
poodle-rb-0.0.8 app/helpers/poodle/flash_helper.rb
poodle-rb-0.0.7 app/helpers/poodle/flash_helper.rb
poodle-rb-0.0.6 app/helpers/poodle/flash_helper.rb