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

时间:2018-04-25 01:09:38

标签: javascript css ruby-on-rails modal-dialog

我所拥有的模态部分保存在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:这是我的Application.js。加载顺序是错误的吗?

//= require rails-ujs
//= require turbolinks
//= require_tree .
//= require jquery3
//= require popper
//= require bootstrap-sprockets

1 个答案:

答案 0 :(得分:0)

<%= 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'%>");