Rails4 + Bootstrap3 - 模态渲染但不会显示

Rails4 + Bootstrap3 - Modals render but won't show

本文关键字:显示 Bootstrap3 模态 Rails4      更新时间:2023-09-26

我正在使用Rails 4,Bootstrap 3。有问题的特定页面由 3 个 haml 视图组成。第一个包含大部分页面内容。第二个包含一排按钮 - 其中一个需要触发模态。第三个包含模态。

第一个视图的代码是:

    <...bulk of page content...>
    = render partial: 'shared/buttons', locals: {diagram: @diagram}
    #showDetail.modal.fade{"aria-labelledby" => "showDetail", :role => dialog, :tabindex => "-1"}

第二个视图的代码("共享/按钮"):

    <...links to several buttons that don't call modals...>
    = link_to "Show Detail", show_detail_path(item), class: "btn", data: {"toggle" => "modal", "target" => "#showDetail", "remote" => :true}

第三个视图的代码(items/_show_detail.html.haml,路由到"show_detail_path"):

    .modal-dialog{:role => "document}
      .my_popup_contain
        .container-fluid
          <...rest of the code for the page...>

在控制器中:

    def show_detail
      render partial: "show_detail"
    end

因此,通过此设置,单击按钮会产生页面"淡入淡出",就像模态将要出现一样,但它永远不会出现。再次单击(任意位置)会使页面淡出(就像显示模态时一样)。rails 服务器日志显示模态确实呈现:

在 2016-02-22 14:49:44 -0600 开始为 127.0.0.1 获取 "/items/4/show_detail" 由 ItemsController#show_detail 作为 JS 进行处理 参数:{"id"=>"4"} 用户负载 (2.1ms) 选择"用户"。* 从"用户"中 "用户"的位置。id" = 1 按"用户"排序。id" ASC 限制 1 项目加载(1.5 毫秒) 选择"项目"。键入"("项目")和"项目"。id" = $1 限制 1 [["id", 4]] 渲染项目/_show_detail.html.haml (1.1ms) 在 11 毫秒内完成 200 OK (浏览次数: 4.7 毫秒 |活动记录:3.6毫秒)

我错过了什么?视图之间的调用是否正确?

通过添加到第一个视图的代码来修复此问题:

    <...bulk of page content...>
    = render partial: 'shared/buttons', locals: {diagram: @diagram}
    #showDetail.modal.fade{"aria-labelledby" => "showDetail", :role => dialog, :tabindex => "-1"}
      = render partial 'items/show_detail'

这调用模态,并且所有工作都按预期工作。