【问题标题】:Devise: update (edit) User via Ajax设计:通过 Ajax 更新(编辑)用户
【发布时间】: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


【解决方案1】:

我通过修改修复了它

if update_resource(resource, account_update_params)

到这里

if resource.update_without_password(params[resource_name])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多