gpt4 book ai didi

ruby-on-rails-4 - 为什么远程 : true and confirm: 'Are You Sure?' not work together?

转载 作者:行者123 更新时间:2023-12-04 23:00:50 26 4
gpt4 key购买 nike

我一直在与 Rails 4 和 UJS 搏斗,并注意到 Rails 4.1 的行为(特别是 rails-ujs)不像我期望的那样。

当使用带有确认对话框的远程链接时,UJS 驱动程序在确认弹出窗口被批准之前发送 XHR(使确认弹出窗口毫无意义)。我本来希望 Rails 能够处理这些选项的组合,但我必须编写自己的 javascript 来执行确认弹出窗口并 Hook 到“ajax:beforeSend”事件以防止请求过早触发。

这是我有什么不起作用的(请求立即触发,没有等待确认对话框返回真):

= link_to 'Ajax Button', app_path(resource), method: :delete, 
remote: true, id: 'ajax_link', disable_with: 'Wait...',
confirm: 'Are you sure?'

这是我现在所拥有的确实有效的:
= link_to 'Ajax Button', app_path(resource), method: :delete,
remote: true, id: 'ajax_link', disable_with: 'Wait...'

$ ->
$("a[data-remote]#ajax_link").on 'ajax:beforeSend', (xhr, settings) ->
return confirm("Are you sure?")

是我还是不应该 rails/jquery-ujs 处理上述选项组合并等待确认弹出窗口?在过去,Rails 3 和更早版本中,远程链接/按钮在处理 AJAX 和远程请求时通常“正常工作”,但在 Rails 4 中,使用 AJAX 似乎需要比以前需要更多的技巧。

有没有其他人在 Rails 4.1 中遇到过这种情况?还有其他解决方案吗?

最佳答案

下面应该工作

= link_to 'Ajax Button', app_path(resource), method: :delete, remote: true, id: 'ajax_link', data: { disable_with: "Wait..." }, data: { confirm: 'Are you sure?' }

关于ruby-on-rails-4 - 为什么远程 : true and confirm: 'Are You Sure?' not work together?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25336544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com