所以我一直在試圖解決這個問題,我已經找到了解決方案。
以我模型(user.rb)我添加:validatable
到下面的代碼片斷:
devise :omniauthable, :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable,
:confirmable, :trackable, reset_password_keys:[:email, :company_id],
request_keys: [:host, :params], omniauth_providers: [:auth0]
在我的註冊控制器
然後,添加以下:
def update_resource(resource, params)
if !params[:password].blank?
resource.password = params[:password]
resource.password_confirmation = params[:password_confirmation]
end
resource.update_without_password(params)
end
最後,在我的應用程序控制器,我將:password_confirmation
添加到以下代碼片段中:
devise_parameter_sanitizer.permit(:account_update) do |u|
u.permit(:first_name, :last_name, :email, :password, :password_confirmation, :phone_number, :receive_emails,
location_attributes: [:id, :street, :city, :state, :zip, :country])
end
通過這種組合,一旦表單被提交,它將落入我已覆蓋的update_resource
塊。它會檢查以確保resource.password
和password_confirmation
是相同的。最重要的是,現在current_password
不在等式中,您不必每次都輸入密碼來保存更改。
我感謝你的幫助,這最終不適合我。我最終發佈了我找到的解決方案 –