【发布时间】:2018-05-09 13:20:01
【问题描述】:
我正在使用 rail4 和 'bootstrap-sass':'3.3.6'。
我已按照https://coderwall.com/p/ej0mhg/open-a-rails-form-with-twitter-bootstrap-modals 中的步骤操作,并根据Bootstrap modal in ruby on rails not working 重写了部分内容。
部分:
<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>
rails 控制台中没有错误。
来自 chrome 检查的响应似乎很好。
回复:
$("#myModal").find(".modal-content").html("<div aria-hidden=\'true\' aria-labelledby=\'myModalLabel\' class=\'modal fade\' id=\'myModal\' role=\'dialog\' tabindex=\'-1\'>\n<div class=\'modal-dialog\' role=\'document\'>\n<div class=\'modal-content\'>\n<div class=\'modal-header\'>\n<h3 id=\'myModalLabel\'>Modal header<\/h3>\n<\/div>\n<div class=\'modal-body\'>\n<p>One fine body…<\/p>\n<\/div>\n<div class=\'modal-footer\'>\n<button aria-hidden=\'true\' class=\'btn\' data-dismiss=\'modal\'>Close<\/button>\n<button class=\'btn btn-primary\'>Save changes<\/button>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n");
$("#myModal").modal('show');
但是模态框没有显示出来。
其他相关代码:
调用该操作的视图:
%li= link_to 'Add release', new_release_path, {:remote => true, 'data-toggle' => "modal", 'data-target' => '#myModal'}
new_release.js.erb
$("#myModal").find(".modal-content").html("<%= j (render 'new_release') %>");
$("#myModal").modal('show');
路线:
get "new_release" => 'project#new_release', :as => :new_release
【问题讨论】:
标签: jquery ruby-on-rails ruby twitter-bootstrap