简体   繁体   English

Twitter Bootstrap Modal在Rails中不显示窗口

[英]Twitter Bootstrap Modal not displaying window in Rails

When I click on the link for my Modal Pop-Up Window, it fades then nothing. 当我单击“模态弹出窗口”的链接时,它消失,然后什么也没有。 I do see a line appear on the page almost like the start of form. 我确实看到页面上几乎像表格的开头一样出现一行。 I have tried many suggestions, to remove hide from the class , realized I had both Bootstrap and Bootstrap-Modal in my application.js , so removed Modal , still no luck. 我尝试了许多建议,以从class删除hide ,意识到我的application.js同时包含了BootstrapBootstrap-Modal ,因此删除了Modal ,但还是没有运气。 Any suggestions/ideas? 有什么建议/想法吗?

My code is in the previous question, which is below. 我的代码在下面的上一个问题中。 I did move my new_release.js.erb into my view/"controller_name" instead of assests/javascripts , like it was suggested. 我确实将new_release.js.erb移到了我的view /“ controller_name”中,而不是像建议的assests/javascripts

Bootstrap Modal(previous question ) Bootstrap Modal(上一个问题

EDITED CODE 编辑代码

Application.js Application.js

//= require bootstrap

Routes.rb Routes.rb

get "project/new_release" => 'project#new_release', :as => :new_release

controller.rb controller.rb

def new_release
respond_to do |format|
format.html
format.js
end
end

project/index.html.erb project / index.html.erb

<div id="modal-window" class="modal hide fade" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true"></div>

<%= link_to 'Add release', new_release_path, remote: true %>

project/_new_release.html.erb project / _new_release.html.erb

<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" style="height:540px; max-height:540px; 
width:630px; max-width:630px;">
Test Modal
</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>

views/project/new_release.js.erb views / project / new_release.js.erb

$("#modal-window").html("<%=j render 'project/new_release' %>");
$('#modal-window').modal('show'); // this will show up your modal once it has its data

development.log development.log

Started GET "/project/new_release" for 123.4.5.6. at Date/Time

AbstractController::ActionNotFound (The action'show' could not be found  
for ProjectController):
....
.... 
(50 lines of actionpack (3.2.13) process, calls, dispatch. journey call, rake call. 
C:/RailsIntaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb)

Rendered C:/RailsIntaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/
actionpack-3.2.13/lib/action_dispatch/middleware/templates/
rescues/unknown_action.erb within rescue/layout

Just checked your code again there are couple of issues 再次检查您的代码,有几个问题

Your modal code 您的模态代码

<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>

is an empty div so it won't show up unless you have width and height on it 是一个空的div,因此除非您有宽度和高度,否则它不会显示

Your link 您的连结

<%= link_to 'Add release', new_release_path, {:remote => true, 'data-toggle'=> "modal", 'data-target' => '#modal-window'}  %>

This will call up js to show your modal which is empty and then add content inside your modal which must be messing it up 这将调用js以显示您的模态为空,然后在模态内添加必须弄乱它的内容

Fix 固定

Without ajax 没有ajax

Your modal should look like: 您的模态应如下所示:

<div id="modal-window" class="modal hide fade" 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">
    **here comes whatever you want to show!**
  </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>

Your link 您的连结

<%= link_to 'Add release', new_release_path, 'data-toggle'=> "modal", 'data-target' => '#modal-window'  %>

With Ajax: 使用Ajax:

Your modal: 您的模态:

<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>

Your link 您的连结

<%= link_to 'Add release', new_release_path, remote: true %>

Your js.erb file 您的js.erb文件

$("#modal-window").html("<%=j render 'project/new_release' %>");
$('#modal-window').modal('show'); // this will show up your modal once it has its data 

对我来说,真正解决此问题的方法是将div类从modal hide fade更改为仅modal

I had the same kind of issue, with a bootstrap modal window not showing up. 我遇到了同样的问题,没有显示引导模态窗口。 I solved the issue by changing class="modal hide fade" to class="modal fade" . 我通过改变解决问题class="modal hide fade"class="modal fade"

There is a tutorial on this ( https://coderwall.com/p/ej0mhg/open-a-rails-form-with-twitter-bootstrap-modals ). 对此有一个教程( https://coderwall.com/p/ej0mhg/open-a-rails-form-with-twitter-bootstrap-modals )。 It's quite concise and works perfectly, only with the modification I mentioned above. 它非常简洁并且可以完美地运行,仅适用于我上面提到的修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM