【问题标题】:Rails4 + Bootstrap3 - Modals render but won't showRails 4 + Bootstrap 3 - 模态渲染但不会显示
【发布时间】:2016-02-22 20:54:06
【问题描述】:

我使用的是 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) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1 项目加载(1.5 毫秒) SELECT "items".* FROM "items" WHERE "items"."type" IN ('Item') AND "items"."id" = $1 LIMIT 1 [["id", 4] ] 渲染项目/_show_detail.html.haml (1.1ms) 在 11 毫秒内完成 200 次 OK(查看次数:4.7 毫秒 | ActiveRecord:3.6 毫秒)

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

【问题讨论】:

    标签: javascript jquery ruby-on-rails twitter-bootstrap modal-dialog


    【解决方案1】:

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

        <...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'
    

    这调用了模态,一切都按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-09
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多