如果对话框没有内容,则不显示 jquery 对话框

don´t display a jquery dialog if the dialog have no content

我的问题是我试图自动捕获闪现消息到 jquery 对话框,但即使没有闪现消息,该对话框也始终显示,因此对话框 window 显示为空白,如何如果没有要显示的 Flash 消息,我可以防止对话框出现吗?坦克 这是我的 js 代码:

$( document ).ready(function() {
$( "#notice" ).dialog({ modal: true });});

这是我application.html.erb

中的代码
<div id="notice">
    <% flash.each do |name, msg| %>
        <%= content_tag :div, msg, :id => "flash_#{name}" %>
    <% end %>
</div>

这是使用 bcrypt 的整个登录实现的一部分,请参阅 railscast #250 Authentication from Scratch

您可以添加有条件地添加布局或模板的末尾。

application.html.erb

<% if !flash.empty? %>
  $("#notice").dialog({ modal: true });});
<% end %>