disable_with 在控制器中使用渲染 js 时无法按预期工作:"window.location=some_path"

disable_with Doesn't work as intended when using render js: "window.location=some_path" in the controller

我目前使用的是Rails5.2.3、simple_form和slim,在Rails.Howeverdisable_with中提交表单时会自动添加disable_with不等待 Javascript 完成渲染并在控制器 returns a 200 时启用提交按钮。

我正在寻找一个通用的解决方案,因为我在多个控制器中遇到了这个问题。

查看

 == simple_form_for some_model, remote: true do |f|
   = f.submit 'Save'

控制器:

def create
 # some class call and business logic
 render js: "window.location='#{path_to_redirect}'"
end

原来这是一个错误,已在 Rails 6 https://github.com/rails/rails/issues/29473

中修复