【发布时间】:2013-11-18 12:01:41
【问题描述】:
我已经成功地通过 Devise 中的 Ajax 进行了登录/注册工作(在博客文章中的一篇文章之后)。但我无法使用 ajax update 操作。我希望用户能够通过 ajax 编辑他的设置,接收正确的 JSON 响应。
因此尝试从 Devise 复制 update 方法,我对其进行了编辑以发回正确的 JSON 响应:
class RegistrationsController < Devise::RegistrationsController
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
if update_resource(resource, account_update_params) # <<< PROBLEM IS HERE
sign_in resource_name, self.resource, :bypass => true
render json: resource, status: :ok
else
clean_up_passwords resource
render json: resource, status: :not_acceptable
end
end
end
这给了我一个错误:
undefined local variable or method "account_update_params"
account_update_params 是 Devise 文件之一中的受保护方法 - 如果我将其复制并粘贴到我的子类:
def account_update_params
devise_parameter_sanitizer.sanitize(:account_update)
end
它给了我下一个错误
devise_parameter_sanitizer not found
看来我走错路了。
【问题讨论】:
-
请尝试
gem 'devise', github: 'plataformatec/devise', branch: 'rails4' -
但我还在 Rails 3 上,可以吗?
-
或试试
before_filter :account_update_params, if: :devise_controller?
标签: ruby-on-rails ajax devise