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! _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
How about using flash[:error]? On 1/8/06, Dylan Markow <dylan@dylanmarkow.com> wrote:> 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] = "<p class=''red''>Error</p>" ? Thanks! > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Hello Dylan, 2006/1/8, Dylan Markow <dylan@dylanmarkow.com>:> 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] = "<p class=''red''>Error</p>" ? 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/
Dylan Markow <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] = "<p > class=''red''>Error</p>" ? 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: <div class="flash warning">Warning here</div> <div class="flash notice">Notice here</div> 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 Raymond scottraymond.net, redgreenblu.com, blinksale.com, iconbuffet.com.