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

「現在のパスワードを空白にすることはできません」というメッセージが引き続き表示されます。devise wiki に従うようにルートを更新すると、次のdevise_for :users, :controllers => { :registrations => "registrations" }エラーが発生します。

Can't mass-assign protected attributes: current_password

これを機能させる方法を知っている人はいますか?

4

1 に答える 1

0

上記の質問コメントの @michael に従って、 を追加attr_accessible :current_passwordUserます。

于 2013-05-08T12:29:36.797 に答える