Flash Messages Helper
A configurable Ruby on Rails view helper for displaying html flash messages in your Rails applications.
Recent Changes
- 0.2.0
- Added a proper configuration DSL
- html_safe called on the output if available
Install as a Ruby Gem
gem install
Rails 2
Then add the following line to your environment.rb
config.gem 'flash_messages_helper'
Rails 3
Add the following to your Gemfile
gem
Installation as a Ruby on Rails Plugin
./script/plugin install git://github.com/mdeering/flash_messages_helper.git
Usage
Once you have installed it as a plugin/gem in your rails app usage is simple. Just call the flash_messages function within you Rails view file
= flash_messages
Configuration
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 use the dom_id configuration attribute.
# config/initializers/flash_messages_helper.rb
FlashMessagesHelper.configure do |config|
config.dom_id = lambda { |key| "#{key}-message" }
end
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 use the css_class configuration attribute.
# config/initializers/flash_messages_helper.rb
FlashMessagesHelper.configure do |config|
config.css_class = lambda { |key| "#{key} dismissible" }
end
A error message will now displayed with the dom element class of _error dismissible rather then error throughout the application
<div class="error dismissible" 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.rb
FlashMessagesHelper.configure do |config|
config.wrapper = :p
end
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 © 2011 Michael Deering, released under the MIT license