Module: Bh::AlertHelper

Includes:
ActionView::Context, ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper
Defined in:
lib/bh/helpers/alert_helper.rb

Instance Method Summary collapse

Instance Method Details

#alert_box(message_or_options_with_block = nil, options = nil, &block) ⇒ String

Returns an HTML block tag that follows the Bootstrap documentation on how to display *alert boxes*. Alert boxes provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages. The message to display in the alert can either be passed as the first parameter (in which case, the options are the second parameter), or as a block (in which case, the options are the first paramter).

Examples:

An alert with a plain-text message passed as the first parameter.

alert 'User updated successfully', dismissible: true

An alert with an HTML message passed as a block.

alert_box dismissible: true do
  <strong>Hooray!</strong> User updated successfully
end

Parameters:

  • message_or_options_with_block (String) (defaults to: nil)

    the message to display in the alert.

  • options (Hash) (defaults to: nil)

    the options for the alert box.

Options Hash (options):

  • :dismissible (Boolean)

    whether to display an ‘×’ to the right of the alert than can be clicked to dismiss the alert.

  • :context (Symbol)

    the contextual class to apply to the alert depending on its importance. Can be :success, :info, :warning, or :danger. Defaults to :info.

  • :priority (Symbol)

    if the alert box is used to show a Rails flash message, the priority of the message. Can be :alert or :notice.

Returns:

  • (String)

    an HTML block tag for an alert.

See Also:



36
37
38
39
40
41
42
# File 'lib/bh/helpers/alert_helper.rb', line 36

def alert_box(message_or_options_with_block = nil, options = nil, &block)
  if block_given?
    alert_string capture_alert(&block), message_or_options_with_block || {}
  else
    alert_string message_or_options_with_block, options || {}
  end
end