gpt4 book ai didi

javascript - 在 Rails 中通过 JS 设计注册#update

转载 作者:数据小太阳 更新时间:2023-10-29 04:30:09 26 4
gpt4 key购买 nike

我正在尝试使用 AJAX 通过 Devise 更新用户模型,并让 Devise 使用正确的 javascript 文件进行响应。

我想远程提交表单到 registrations#update 操作,但这不适用于 Devise 的默认响应,它使用来自 RegistrationsController 的以下内容:

respond_with resource, :location => after_update_path_for(resource)

以上尝试重定向到默认路由,而不是呈现 update.js.erb 文件。我能够覆盖该操作并使其适用于以下更改:

respond_to do |format|
format.html
format.js
end

但是,这似乎非常蛮力,因为我正在覆盖整个操作。是否有一种简单的方法让 Devise 知道使用 javascript 响应而不是进行默认重定向?

最佳答案

只需向 RegistrationsController 添加一行,以便 Devise 知道响应 html 和 js。

class RegistrationsController < Devise::RegistrationsController
respond_to :html, :js
end

阅读 respond_with 的真正帮助。几个好的链接:

Rails API Responder

AsciiCast

关于javascript - 在 Rails 中通过 JS 设计注册#update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16348724/

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