如何使Rails中的Flash消息超时 [英] How to timeout flash messages in rails

查看:64
本文介绍了如何使Rails中的Flash消息超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前拥有带有成功/失败等设计器标准消息的标准Flash消息.我添加了通过close类通过一些引导程序功能手动关闭消息的选项.一个小片段如下所示.

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 via a close class. A small snippet is shown below.

{ 
  <a class="close" data-dismiss="alert">&#215;</a>
  <%= content_tag :div, msg, :id => "flash_#{name}" %>
}

我想选择一个超时时间段,在该时间段内,警报消息将在5秒后关闭.不确定在Rails中是否有一种简单的方法.

I was would like to have an option to create a timeout period where the alert message would close on its one after 5 seconds. Not sure if there is a simple way to do this in Rails.

谢谢

推荐答案

如果您在同一页面上加载了jQuery,这将为您工作

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>

这篇关于如何使Rails中的Flash消息超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆