我正在尝试实现一个模式来为我的应用创建一个新用户。由于某种原因,无法使其发挥作用。
此代码只是淡入淡出,没有模态出现,我无法弄清楚原因。事实上,我使用的是与此答案完全相同的代码How to add bootstrap modal with link_to so the link content open in modal ?
<%= link_to "Open modal", "#myModal", :class => "btn", "data-toggle" => "modal" %>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
我的宝石:
gem 'rails', '5.0.2'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
gem 'faker', '1.6.6'
gem 'will_paginate', '3.1.0'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bcrypt', '3.1.11'
gem 'bootstrap-sass', '3.3.6'
gem 'puma', '3.4.0'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.0.0'
gem 'coffee-rails', '4.2.1'
gem 'jquery-rails', '4.1.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.4.1'
app/assets/javascripts/application.js
行
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-sprockets
我的scss
@import "bootstrap-sprockets";
@import "bootstrap";
答案 0 :(得分:2)
您需要从hide
模式中删除#myModal
类,因为它为display: none !important
CSS规则提供了一个,这就是您无法看到它的原因:
检查:
<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
最有可能的是,您需要将.modal-header
包裹在<div class="modal-dialog" role="document">
和<div class="modal-content">
内,以便“很好”地看到它。
答案 1 :(得分:0)
模态将在显示后立即消失。所以我在application.js文件中删除了// = require bootstrap-sprockets并解决了这个问题。 FYI