【发布时间】:2017-12-04 23:37:56
【问题描述】:
我有一个带有编辑模式的 Rails 应用程序。提交功能有效,但关闭按钮不执行任何操作。
Edit.js.erb:
$("#modal-window").html("<%= escape_javascript(render 'users/edit') %>");
_edit.html.erb
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<%= form_for @user,url: root_path,:method => :GET do |f|%>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<%# submit_tag 'Cancel', :type => :reset, :class => "btn btn-danger", "data-dismiss" => "modal", "aria-hidden" => "true" %>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
从视图中打开和容纳模态的线条
<%= link_to 'Edit Password', edit_path(user.id), {:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'}
......
<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
我已经设置好了宝石。 //= require bootstrap/modal 和 //= require jquery 在我的 application.js 中
编辑:完整的application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require_tree .
//= require bootstrap/modal
//= require jquery
【问题讨论】:
-
您的 application.js 文件中还包含哪些其他 .js 文件?
-
@Rohit 查看编辑
-
您只需添加“//= require jquery_ujs”。如果这也不起作用,需要最新的 jquery、jquery ui 和 bootstrap..
-
完成,没有变化@Rohit
-
您是否尝试在 application.js 文件中的 gem 之前添加 jquery?
标签: jquery ruby-on-rails twitter-bootstrap bootstrap-modal