0

当我关闭模式(在模式外单击)时,网页仍然很暗,我必须再次点击页面上的某个位置才能再次正常显示。任何人都知道问题可能是什么?Rails页面加载模态背景两次?

_post_modal.html.erb

<div id="<%= p.id %>" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-header"> 
     <p><h3 id="myModalLabel"><%= p.title %></h3></p> 
    </div> 
    <div class="modal-body"> 
     <%= raw(p.link) %> 
    </div> 
</div> 

_single_post.html.erb

<% @posts.each do |p| %> 
    <%= render "post_modal" %> 
<% end %> 

list.html.erb

<div class="container"> 
    <%= render 'single_post' %> 
</div> 

application.html.erb

<body> 
    <%= link_to('Logout user', destroy_user_session_path, :method => :delete) %> 
    <%= link_to('Logout admin', destroy_admin_session_path, :method => :delete) %> 
    <%= yield %> 
</body> 

custom.css.scss

body{ 
     background-image:url('dark_leather.png'); 
     color: #333; 
     font-family: verdana, arial, helvetica, sans-serif; 
     line-height: 18px; 
} 

.container{ 
    vertical-align: center; 
} 

.modal{ 
    h3{ 
     font-family: 'Josefin Slab', serif; 
     font-size: 18pt; 
     font-weight: 400; 
     color: #34DDDD; 
    } 
} 
+0

于是我发现了(从“检查元素”在Chrome),该页面打开两个'

' ,而不只是一个。这是我必须点击两次才能使黑色覆盖层消失的原因。那么我怎样才能让它开放一次(而不是两次)呢? – allegutta

回答

0

后googleing和阅读的时间,我找到了解决办法。

我第一次发现this,这导致我this,这导致我this。 (因为它提供了替代解决方案和解释)。

简而言之:

1)首先,我添加了这个:config.serve_static_assets = falseconfig/environments/development.rb文件。

2)然后我在终端运行rake assets:clean命令。

3)最后我在浏览器中删除了缓存。

它的工作 - 为什么它的工作,是写在上面的链接很长的解释;)

2

隐藏在做AJAX请求之前的模式。我有同样的问题,并解决了它。对我来说,更换包含实际模态窗口的容器是一个更大的问题。

如果不工作,你总是可以迫使它这样做走开如下:

$('#your-modal-id').modal('hide'); 
$('body').removeClass('modal-open'); 
$('.modal-backdrop').remove(); 
+0

嗨矢量,感谢您的答案,但你是什么意思与“隐藏模式之前做Ajax请求”?我怎样才能做到这一点? – allegutta

+0

向量,你刚刚复制了这个答案...(http://stackoverflow.com/questions/11519660/twitter-bootstrap-modal-backdrop-doesnt-disappear) – allegutta

+0

这解决了我的问题。 – Vector