问题描述
我想通过设计来更新用户模型AJAX和具有设计与适当的JavaScript文件。
I'm trying to update the User model through Devise with AJAX and have Devise respond with the proper javascript file.
我要远程提交表单的注册#更新操作,但是这不工作从制定默认响应,它使用从RegistrationsController如下:
I want to submit the form remotely to the registrations#update action, but this isn't working with the default response from Devise, which uses the following from the RegistrationsController:
respond_with resource, :location => after_update_path_for(resource)
以上设法重新渲染update.js.erb文件的缺省路由来代替。我能够覆盖行动,并把它与下面的变化工作:
The above tries to redirect to the default route instead of rendering the update.js.erb file. I am able to overwrite the action and have it work with the following change:
respond_to do |format|
format.html
format.js
end
不过,这似乎很蛮力因为我重写了整个行动。有一个简单的办法制订知道该用JavaScript回应,而不是做它的默认重定向?
But, this seems very brute force as I'm overriding the entire action. Is there a simple way for Devise to know to respond with javascript instead of doing its default redirect?
推荐答案
只是有一条线添加到RegistrationsController使设计明知的respond_to HTML和JS。
Simply had to add a line to the RegistrationsController so that Devise knows to respond_to both html and js.
class RegistrationsController < Devise::RegistrationsController
respond_to :html, :js
end
在阅读关于如何respond_with真正帮助。对很好的链接:
Reading up on how respond_with really helped. Couple of good links:
这篇关于通过JS在滑轨设计注册#更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!