<% if flash[:warning] or flash[:notice] %> <div id="notice" <% if flash[:warning] %>class="warning"<% end %>> <%= flash[:warning] || flash[:notice] %> </div> <script type="text/javascript"> setTimeout("new Effect.Fade('notice');", 15000) </script> <% end %>
Nice one though! Love it and using it right now... Only thing left to do it making it fade in before fading out :)
<% flash.each do |key, msg| %> <%= content_tag :div, msg, :class => "flash", :id => key %> <% content_tag :script, :type => "text/javascript" do %> $('<%= key %>').style.display = 'none'; new Effect.Appear('<%= key %>', {duration: 3}); <% end %> <% content_tag :script, :type => "text/javascript" do %> setTimeout("new Effect.Fade('<%= key %>');", 10000); <% end %> <% end %>
for some reason it did not work when I just set the .flash class in my stylesheet to display: none;
<%= content_tag :script, :type => "text/javascript" do -%>
(!!)
You need to create an account or log in to post comments to this site.
Now you have a completely flexible solution. Add as many key to your flash as you want and you only need those 6 lines of code to handle it all; be it errors, notices, warnings, or some uber prize alert!
** WARNING ** : Use with caution. Sugary syntax can be highly addictive. Use with discretion. ;)