On Feb 21, 2008, at 10:14 AM, Arlen Cuss wrote:
> Hiya,
>
> On Fri, Feb 22, 2008 at 2:07 AM, Jigar Gosar <jigar.gosar@gmail.com>
> wrote:
>
>> The "if v" can be removed, cause if the key exists than there is no
>> problem in rendering its value.
>
> Good point, I'm asleep!
>
> Thanks a lot, that was a really quick reply.
>
> No problems.
>
>
>> I just love ruby, cause so much can be expressed in so less.
>
> You're absolutely right.
I recently read a good article to this
> effect:
> "Do not learn Ruby"
> http://webmat.wordpress.com/2008/02/...ot-learn-ruby/. It's a
> fun read.
>
> Cheers,
> Arlen.
Or put one of these in your application_er (not both, or combine
them yourself) (Apologies for the inevitable email wrapping ;-)
module Applicationer
COLORS = Hash.new('#ff0000').merge!({ :notice => '#00ff00',
:warning => '#ff9900',
:error => '#ff0000',
}) unless const_defined? 'COLORS'
# Shows the flash message(s) with a highlight effect
def flash_div(*keys)
keys.collect { |key|
content_tag(:div, flash[key],
:id => "#{key}",
:class => "flash") if flash[key]
}.join +
keys.collect { |key|
javascript_tag(visual_effect(:highlight, "#{key}",
:startcolor => "'#{COLORS[key]}'",
:endcolor => "'#ffffff'")) if
flash[key]
}.join
end
# Shows the flash message(s), but they go away when clicked. An
options hash will be applied to a surrounding div tag.
def flash_div(*keys)
return '' if keys.blank?
options = { :id => 'flash' }
options.update(keys.pop) if keys.last.is_a? Hash
content_tag(:div,
keys.collect { |key|
content_tag(:div,
flash[key], :id => "#{key}-
flash", :class => "#{key} section",

nClick => "new Effect.Fade(this);")
if flash[key]
}.join,
options)
end
end
And then in your views (or layout):
<%= flash_div :notice, :warning, :error -%>
Then toss in some CSS to taste and serve warm.
-Rob
Rob Biedenharn
http://agileconsultingllc.com
Rob@AgileConsultingLLC.com