Rails 替换 confirm with Zurb 基础模态 - Uncatch TypeError: confirm

Rails replace confirm with Zurb foundation modal - Uncaught TypeError: confirmWithReveal is not a function

本文关键字:confirm Uncatch TypeError 模态 替换 with Zurb Rails      更新时间:2023-09-26

让我先说,我不擅长javascript。如果我错过了一些明显的东西,请原谅我。

我想将标准确认对话框替换为基础模式对话框。有人可以帮助我在页面中构建正确的结构吗?我在index.html.erb页面上有以下link_to:

<%= link_to 'Delete', post, method: :delete, data: { confirm: "Are you sure?" }, class: "tiny radius button" %>

我注意到当页面加载时,我在控制台中收到一个错误:

Uncaught TypeError: $(...).confirmWithReveal is not a function

此错误似乎出现在每个页面上。我明确定义的模式对话框适用于其他页面。

我做了一些研究,找不到任何明确的例子来说明如何做到这一点。此页显示了确认的各种样式,但不显示如何在 <%= link_to ... %> 表达式中使其工作。

confirm_with_reveal不是Foundation的一部分,而是一个额外的模块。以下是我使用它的步骤:

  1. 放置来自 GitHub 存储库的源文件之一,例如 confirm_with_reveal.js到您的 rails 的 vendor/assets/javascripts/confirm_with_reveal.js 文件夹中。通常我将存储库添加为子模块,但这取决于您。
  2. 添加到app/assets/javascripts/application.js

    //= require jquery
    //= require jquery_ujs
    //= require confirm_with_reveal/confirm_with_reveal
    $(function(){
      $(document).confirmWithReveal();
    });
    
  3. 重写您的标准导轨确认自

    link_to 'Delete', post, method: :delete, data: { confirm: "Are you sure?" }, class: "tiny radius button" %>
    

    link_to 'Delete', post, method: :delete, data: { confirm: {title:"Are you sure?"} }, class: "tiny radius button" %>
    

    并尝试使用您在自述文件中找到的属性。

  4. 此外,如果您使用 foundation 6,则必须修改 javascript 并在第 54 行中替换:

    modal.foundation('reveal', 'close');
    

    modal.foundation('close');
    

    在第 68 行:

    foundation('reveal', 'open')
    

    foundation('open')