Custom flash[:notice]


#1

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#2

How about using flash[:error]?


#3

Hello Dylan,

2006/1/8, Dylan M. 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/

[1] https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/


#4

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, redgreenblu.com, blinksale.com, iconbuffet.com.