2

我知道这个问题已经被问过好几次了,每个答案都会导致设计 wiki,但我无法让它工作。我在这里关注了 wiki 和其他一些帖子,但没有运气。我想让用户更新他的信息(电子邮件、用户名、姓名等),而不必每次都输入密码。

我的registrations_controller.rb样子是这样的:

class RegistrationsController < Devise::RegistrationsController
  def update
    # required for settings form to submit when password is left blank
    if params[:user][:password].blank?
      params[:user].delete("password")
      params[:user].delete("password_confirmation")
    end

    @user = User.find(current_user.id)
    if @user.update_attributes(params[:user])
      # Sign in the user bypassing validation in case his password changed
      sign_in @user, :bypass => true
      redirect_to root_path
    else
      render "edit"
    end
  end
end

我的routes.rb样子是这样的:

Sparechef::Application.routes.draw do
  get "users/profile"

  devise_for :users
  devise_for :controllers => { :registrations => "registrations" }
  resources :dashboard

  root to: "home#index"

  match "profile" => "users#profile"
end

我仍然收到消息“当前密码不能为空”。如果我更新我的路线以遵循设计 wiki,devise_for :users, :controllers => { :registrations => "registrations" }我会收到此错误:

Can't mass-assign protected attributes: current_password

有人知道如何让它工作吗?

4

1 回答 1

0

根据上述问题评论中的@michael,添加attr_accessible :current_password.User

于 2013-05-08T12:29:36.797 回答