Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A simple and configurable Rails view helper for displaying flash messages.
Ruby
tree: 05469e24b8
Failed to load latest commit information.
lib fix of configuration errors
rails Prepping everything as I put in place what is needed to get this plug…
spec changed the README to match the new configuration DSL.
.gitignore added deprecation warnings and setup the project with bundler.
Gemfile added deprecation warnings and setup the project with bundler.
Gemfile.lock added deprecation warnings and setup the project with bundler.
MIT-LICENSE Initial commit if the most basic helper taken from http://www.teachme…
README.textile fix of configuration errors
Rakefile Prepping everything as I put in place what is needed to get this plug…
VERSION Version bump to 0.2.1
flash_messages_helper.gemspec Regenerate gemspec for version 0.2.1
install.rb
install.txt Prepping everything as I put in place what is needed to get this plug…
uninstall.rb Prepping everything as I put in place what is needed to get this plug…

README.textile

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 flash_messages_helper

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 ‘flash_messages_helper’

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

Something went wrong with that request. Please try again.