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 工夫バージョン:あなたのpassword
とpassword_confirmation
を追加する必要がaccount_update_params
方法で4.2.0
チャーンを試してもうまくいきませんでした。 =/ – user1301037
パスワードの更新中に開発ログにエラーが発生しました –
いいえ、編集ビューでpasswordとconfirm_fieldのフィールドを編集した後、私はsucessメッセージでルートにリダイレクトされますが、新しいパスワードは渡されません。 ログには次のように表示されます。 - Completed 401 Unauthorized in 259ms(ActiveRecord:1.1ms) – user1301037