我以前見過這個帖子,但還沒有找到適合我的解決方案。Rails - 如何爲omniauth用戶重寫Devise'當前密碼'
我曾嘗試下面的設計的Wiki,並試圖通過他人建議的代碼添加到控制器: Editing Users With Devise and Omniauth [Rails]update_without_password does't update user info https://github.com/plataformatec/devise/issues/1620
問題是,通過我們的Twitter Omniauth用戶註冊後無法更新他們的賬戶信息,因爲設計提示他們的'當前密碼'進行更改。通過電子郵件向用戶發送隨機生成的密碼不是一種選擇。
我想做什麼 -
我想覆蓋設計控制器的「更新」方法使其能夠識別一個Twitter用戶編輯自己的詳細信息在第一時間,並允許他們跳過「當前密碼」驗證。我們爲Twitter用戶分配一個標準的電子郵件地址,該地址可以是它檢查的變量。如果不更改,他們將無法提交。
仍是問題 -
我試過在登記控制器不同的代碼塊,但我還是很正從一個錯誤,當前密碼不正確重定向回。我甚至沒有進入binding.pry,所以它看起來像甚至沒有被讀取的方法?
我已經嘗試徹底刪除'當前密碼'的表單輸入,並將其隱藏傳遞給默認值。
謝謝你的幫助!
路線
Rails.application.routes.draw do
ActiveAdmin.routes(self)
# devise_for :users,
devise_for :users, controllers: { registrations: 'registrations' },
controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
scope '(:locale)', locale: /en|ca|es/ do
resources :politicians
resources :posts do
resources :comments, only:[:new, :create, :edit, :update, :destroy]
member do
put "like", to: "posts#upvote"
put "dislike", to: "posts#downvote"
end
end
get "/about" => "pages#about_us"
root to: 'pages#home'
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Registrations_Controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
protected
def update_resource(resource, params)
binding.pry
if current_user.email.include?("email.com")
params.delete("current_password")
resource.update_without_password(params)
else
resource.update_with_password(params)
end
end
end
[編輯用戶設計和Omniauth]的可能的複製(https://stackoverflow.com/questions/13436232/editing-users-with-devise-and-omniauth) – Gerry