Forum: Ruby on Rails Custom flash[:notice]

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D9d1b31a337f46ac5e4dd56b55404f58?d=identicon&s=25 Dylan Markow (Guest)
on 2006-01-09 03:49
(Received via mailing list)
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Accad816054fc1b2fa7dae2a2fce5266?d=identicon&s=25 Cuong Tran (Guest)
on 2006-01-09 04:13
(Received via mailing list)
How about using flash[:error]?
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 Francois Beausoleil (Guest)
on 2006-01-09 04:20
(Received via mailing list)
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_plug...
F1b7ae83e1cbd480d3342945199d8c60?d=identicon&s=25 Scott Raymond (Guest)
on 2006-01-09 05:02
(Received via mailing list)
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.
This topic is locked and can not be replied to.