public
Description: A simple yet configurable rails view helper for displaying flash messages.
Homepage:
Clone URL: git://github.com/mdeering/flash_messages_helper.git
README.textile

Flash Messages Helper

Ruby on Rails view helper for displaying html flash messages in your Rails applications.

Installation as a Ruby on Rails Plugin

The traditional way.

./script/plugin install git://github.com/mdeering/flash_messages_helper.git

or the old-school but still c00l way!

piston import git://github.com/mdeering/flash_messages_helper.git vendor/plugins/flash_messages_helper

or for all you hip gitsters.

git submodule add git://github.com/mdeering/flash_messages_helper.git vendor/plugins/flash_messages_helper git submodule init

Usage

Once you have installed it as a plugin for your rails app usage is simple. Just call the flash_messages function within you Rails layout or view file

flash_messages

Configuration Points

Changing the default id of the flash elements

By default the id of the flash message element will come through as flash-error-type

  • flash-error
  • flash-notice
  • flash-warning
  • ect…

To change this you can pass set a lambda that will get called with the key of the message type.

# config/initializers/flash_messages_helper_settings.rb
ActionView::Base.flash_message_id_proc = lambda {|key| "#{key}-message"}

A error message will now displayed with the dom element id of error-message rather then flash-error throughout the application

<div class="error" id="error-message">There was an error!</div>

Changing the default class of the flash elements

By default the class of the flash message element will come through as error-type

  • error
  • notice
  • warning
  • ect…

To change this you can pass set a lambda that will get called with the key of the message type.

# config/initializers/flash_messages_helper_settings.rb
ActionView::Base.flash_message_class_proc = lambda {|key| "#{key} hideable"}

A error message will now displayed with the dom element class of _error hideable rather then error throughout the application

<div class="error hideable" id="flash-error">There was an error!</div>

Changing the default html tag type of the flash elements

As a default the html tag used to wrap the flash messages is a div element. This can be easily globally changed with the following setting.

# config/initializers/flash_messages_helper_settings.rb
ActionView::Base.flash_message_tag = :p

With the above setting flash messages will be wrapped inside of a paragraph tag rather then a div.

<p class="error" id="flash-error">There was an error!</p>

Credits

Copyright © 2009 Michael Deering, released under the MIT license