How to timeout flash messages in rails

后端 未结 2 445
予麋鹿
予麋鹿 2021-02-05 19:30

I currently have standard flash messages with the devise gem for success/failure etc. I have added the option to manually close the message with some bootstrap functionality vi

相关标签:
2条回答
  • 2021-02-05 19:59
    1. Ensure that your div has an alert class.
    2. Add the following code in your application.js or other .js file:
    $(document).on('turbolinks:load', function() {
      setTimeout(function() {
        $('.alert').fadeOut();
      }, 3000);
    })
    
    
    1. Watch it go away.
    0 讨论(0)
  • 2021-02-05 20:03

    If you've jQuery loaded in the same page, this will work for you

    <div id="flash">
      <a class="close" data-dismiss="alert">&#215;</a>
      <%= content_tag :div, msg, :id => "flash_#{name}" %>
    </div>
    
    <script type="text/javascript">
    $(document).ready(function(){
      setTimeout(function(){
        $('#flash').remove();
      }, 5000);
     })
    </script>
    
    0 讨论(0)
提交回复
热议问题