0

我用下面的代碼來自動駁回on Rails應用程序在我的紅寶石的成功提醒:自動辭退引導警報停在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

有沒有完成我想要完成什麼更好的辦法?有沒有人看到我正在做的事情可能導致它停止工作的任何錯誤?我希望我能說當它停止工作,但我剛纔注意到。

回答

0

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

這是我如何使用它

將此代碼添加到application.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') 
    }