I have been extracting and abstracting many of the components that I use across most of the Ruby on Rails applications that I work with and putting them up on GitHub as gems and Rails plugins. Here is another one (Flash Messages Helper) and I still have a lot more where these have been coming from.
Cheers, I hope you have a use for them.
I am in no way the first person to create a flash message plugin, but the other plugins that I did come across lacked any type of configuration or flexibility, so I ended up rolling my own.
Install
./script/plugin install git://github.com/mdeering/flash_messages_helper.git
After installing the plugin you just need to replace your flash message calls with the following in your layout file.
flash_messages
The configuration points of the plugin include being able to change the id and class attriubtes of the elements along with the type of element that actually wraps your flash messages. See the full documentation over on the flash_messages_helper plugin page at GitHub
Example Usage
I like to add a class hideable to all flash messages and then use jQuery to allow the user to remove the flash message elements from the page if they like.
# config/initilizers/flash_messages_helper_settings.rb
ActionView::Base.flash_message_class_proc = lambda {|key| "#{key} hideable"}
Now all flash messages will come out with the class hideable. We can unobtrusively attach the hiding behavor to the element with the following jQuery.
$(document).ready(function(){
// Will add a link at the bottom of any element that is hiddable
$.each($('.hideable'), function() {
$(this).append('<a class="#">Hide</a>');
});
// And this will actualy do the hiding of the parent element
$('a.hide-link').click(function() {
$(this).parent().hide('slow');
return false
});
});
Do me a quick favor if end up using some of my work. Take the time to Recommend me on Working With Rails , give me or one my repos a follow over on Github , follow me over on Twitter , or all of the above.