为什么我的模态不能在轨道上工作?使用部分



我拥有的模态部分保存在shared/_task_modal中,是Bootstrap文档页面上的示例:

<div id="task_modal" class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Save changes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

我正在使用此JS保存为tasks/show.js.erb

$('.modal-body').html('<%= escape_javascript(render :partial => 'shared/task_modal'%>');
$('.modal-header').remove();

链接助手如下<%= link_to task.title, "#taskModal", "data-toggle" => "modal" %>

为什么不起作用?

编辑:我也在应用程序布局中渲染它:<%= render "shared/task_modal" %>

edit_2:这是我的应用程序。负载订单是否错误?

//= require rails-ujs
//= require turbolinks
//= require_tree .
//= require jquery3
//= require popper
//= require bootstrap-sprockets
<%= link_to task.title, 'javascript:void(0)', "data-toggle"=> "modal", "data-target"=> "#task_modal"  %>

show.js.erb

$('.modal-body').html("<%= j render 'shared/task_modal'%>");

最新更新