自动关闭引导警报在 Rails 中停止工作

Auto Dismiss Bootstrap Alert stopped working in Rails

本文关键字:Rails 停止工作      更新时间:2023-09-26

我使用以下代码在我的Ruby on Rails应用程序中自动消除成功警报:

$ ->
  flashCallback = ->
    $(".alert-success").fadeOut()
  $(".alert-success").bind 'click', (ev) =>
    $(".alert-success").fadeOut()
  setTimeout flashCallback, 3000

相关警报行为:

<div class="alert alert-<%= name.to_s == "notice" ? "success" : "danger" %> alert-dismissable">

一切都很好,但似乎在途中的某个地方坏了。

我的所有代码都可以在这里找到:https://github.com/vroomanj/updemo

有没有更好的方法来完成我想完成的事情?有没有人看到我正在做的事情有什么问题,可能导致它停止工作?我希望我能说它何时停止工作,但我刚刚注意到。

使用 Noty http://ned.im/noty/#/about

这就是我使用它的方式

将此代码添加到应用程序.js.coffee

window.show_notification = (text, type)->
  n = noty({
    layout: 'topRight'
    text: text
    type: type
    theme: 'relax'
    animation:
      open: "animated bounceInRight"
      close: "animated fadeOut"
  })
  setTimeout (->
      n.close()
    ), 5000

我的 Flash 消息部分采用纤薄格式

javascript:
  if(#{flash[:notice].present?}){
    show_notification("<span class= 'fa fa-check-circle'></span> #{flash[:notice]}", 'success')
  }
  if(#{flash[:alert].present?}){
    show_notification("<span class= 'fa fa-exclamation-circle '></span> #{flash[:alert]}", 'error')
  }