我有如下表:設計:如何驗證與其他模型有關係的用戶?
users
======
id
email
password
..device columns..
providers
==========
user_id
..irreverent columns..
consumers
==========
user_id
..irrelevant columns..
消費者和供應商都屬於users
表,我們採用這樣的設計,因爲有網絡應用程序,雙方都可以訪問的地方,但是,有時會出現是消費者不應該在的提供商特定領域,例如提供商管理面板。
因此,這提出了以下問題,當我們只知道用戶表而不知道提供者/消費者時,我如何才能讓Devise只驗證提供者而不是提供者特定命名空間的消費者?
這裏就是我想我應該做的:
控制器/供應商/ base_controller.rb:
before_action :authenticate_provider!
private
#A modified wrapper around authenticate_user!
def authenticate_provider!
authenticate_user!
redirect_to sign_in_path unless Provider.find_by(user: current_user)
end
小心這些不敬的專欄 – Slicedpan
更嚴重的問題是,您提出的解決方案有什麼問題? – Slicedpan
@Slicedpan其實並沒有什麼,我只是期待一個更優雅的解決方案,或許是Devise開箱即用的功能。 – Abdulaziz