Search code examples
jqueryruby-on-railsrubyflash

auto hide the flash messages in rails


I need to auto fade the flash messages in ruby on rails.

My message code is:

<%= simple_form_for(@dashboard_user) do |f| %>
<% if @dashboard_user.errors.any? %>
<ul class="alert alert-danger">
    <% for message_error in @dashboard_user.errors.full_messages %>
    <li>
        <%= message_error %>
    </li>
    <% end %>
</ul>
<% end %>

How i auto fade these messages?


Solution

  • This should work for you. You can specify the time span within the brackets. Add this to your Javascript. this is common for all:

    $(".alert" ).fadeOut(3000);
    

    For alert success:

     $(".alert-success" ).fadeOut(3000);
    

    For alert danger:

    $(".alert-danger" ).fadeOut(3000);