# Custom flash\[:notice\]

**URL:** <https://www.ruby-forum.com/t/custom-flash-notice/94781>\
**Category:** Rails\
**Created:** [January 9, 2006, 3:49am UTC](https://www.ruby-forum.com/t/custom-flash-notice/94781 "2006-01-09T03:49:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [January 9, 2006, 3:49am UTC](https://www.ruby-forum.com/t/custom-flash-notice/94781/1 "2006-01-09T03:49:44Z")

</div>

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [January 9, 2006, 4:13am UTC](https://www.ruby-forum.com/t/custom-flash-notice/94781/2 "2006-01-09T04:13:54Z")

</div>

How about using flash[:error]?

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [January 9, 2006, 4:20am UTC](https://www.ruby-forum.com/t/custom-flash-notice/94781/3 "2006-01-09T04:20:00Z")

</div>

Hello Dylan,

2006/1/8, Dylan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> For the most part, my flash[:notice] messages fall into one of two  
> categories: either a message stating that something happened successfully  
> (which is colored green), or messages showing errors (which I would like to  
> be red).
> 
> Is it possible to set some sort of flag on these messages to choose which  
> color I want to show, or would I need to base it on CSS and set the class in  
> the text, i.e. flash[:notice] = “
> 
> Error
> 
> ” ? Thanks!

There’s nothing preventing you from adding more than one type of  
message to the flash. For example, the Flash Helper Plugin[1] adds up  
to three types of messages to the flash: notice, message and warning.  
These are then marked up appropriately with CSS classes while being  
displayed.

## Hope that helps !

FranÃ§ois Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)

[1] [https://opensvn.csie.org/traccgi/flash\_helper\_plugin/trac.cgi/](https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/)

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [January 9, 2006, 5:02am UTC](https://www.ruby-forum.com/t/custom-flash-notice/94781/4 "2006-01-09T05:02:12Z")

</div>

Dylan M. \<dylan@…\> writes:

> Is it possible to set some sort of flag on these messages to choose  
> which color I want to show, or would I need to base it on CSS and set  
> the class in the text, i.e. flash[:notice] = “
> 
> Error
> 
> ” ? Thanks!

I generally like to add something like this to my application\_helper.rb:

def flash\_div \*keys  
keys.collect { |key| content\_tag(:div, flash[key],  
:class =\> “flash #{key}”) if  
flash[key] }.join  
end

…and then this in my layouts/application.rhtml:

\<%= flash\_div :warning, :notice %\>

Now, if my controller puts anything into flash[:warning] or  
flash[:notice],  
they’ll render like:

Warning here

Notice here

Nice and DRY, and easy to style. If I ever need some other flash key  
besides :warning or :notice, I can just add an argument to the flash\_div  
call  
and I’m set.

Scott R.  
[scottraymond.net](http://scottraymond.net), [redgreenblu.com](http://redgreenblu.com), [blinksale.com](http://blinksale.com), [iconbuffet.com](http://iconbuffet.com).
