2016-09-24 13 views
0

deviseによって生成されたユーザースコープコントローラを使用して、追加の属性を渡しています。Devise Issue - ユーザーがパスワードなしで編集できるようにする

class Users::RegistrationsController < Devise::RegistrationsController 
before_action :sign_up_params, only: [:create] 
before_action :account_update_params, only: [:update 

protected 

    def sign_up_params 
    devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :cpf]) 
    end 

    def account_update_params 
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :cpf, :birth_date, :phone, :gender]) 
    end 

def update_resource(resource, params) 
    resource.update_without_password(params) 
end 

end 

devise_for :users, controllers: {registrations: 'users/registrations} 

すべてが働いていたルートコントローラにupdate_resource(リソース、paramsは)方法を含み、https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password

示唆されるように、ビューで current_passwordフィールドを削除するまで

この変更後、パスワード以外のすべての追加フィールド(first_name、last_name ...など)を編集できます。パスワードの変更は維持されません。何か案が?

Railsのバージョン:5.0.0.1 工夫バージョン:あなたのpasswordpassword_confirmationを追加する必要がaccount_update_params方法で4.2.0

答えて

0

def account_update_params 
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :cpf, :birth_date, :phone, :gender, :password, :password_confirmation]) 
end 
+0

チャーンを試してもうまくいきませんでした。 =/ – user1301037

+0

パスワードの更新中に開発ログにエラーが発生しました –

+0

いいえ、編集ビューでpasswordとconfirm_fieldのフィールドを編集した後、私はsucessメッセージでルートにリダイレクトされますが、新しいパスワードは渡されません。 ログには次のように表示されます。 - Completed 401 Unauthorized in 259ms(ActiveRecord:1.1ms) – user1301037

関連する問題