したがって、Facebook 経由で認証された場合にユーザーを編集するためのデバイス パスワード要件を回避することについて、およそ 50 万件の質問があることを私は知っています。私はそれらの少なくとも 75% を読んだことを約束しますが、まだこれを理解することはできません.
基本的に、Carl Edward & Laurie Laine の SO answer here に従って、Devise の登録コントローラーを作成しました。これにより、ユーザーがアカウントを編集していて、ユーザーが Facebook からログインしている場合にパスワードの検証をバイパスできます。次のコードでは、最終的にエラーはスローされませんが、更新された属性は保存されません。
class RegistrationsController < Devise::RegistrationsController
def update_resource(resource, params)
if current_user.provider == "facebook"
params.delete("current_password")
resource.update_without_password(params)
else
resource.update_with_password(params)
end
end
def update
account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
# required for settings form to submit when password is left blank
if account_update_params[:password].blank?
account_update_params.delete("password")
account_update_params.delete("password_confirmation")
end
@user = User.find(current_user.id)
if @user.update_attributes(account_update_params)
@user.update(account_update_params)
set_flash_message :notice, :updated
update_resource(@user,account_update_params)
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
end
私は文字通り自分が間違っていることを理解できませんが、Facebookによって認証されたログインユーザーとしてユーザープロファイルを更新しようとするたびに、プロファイルやコンソールでデータベースにクエリを実行しても何も変わりません.