【发布时间】:2013-12-18 17:06:03
【问题描述】:
我有以下表格:
users
======
id
email
password
..device columns..
providers
==========
user_id
..irreverent columns..
consumers
==========
user_id
..irrelevant columns..
消费者和提供者都属于users 表,我们使用这种设计是因为双方都可以访问网络应用程序的某些区域,但是,有时存在消费者不应该访问的特定于提供者的区域在,如供应商管理面板。
所以这引发了以下问题,当 Devise 只知道用户表而不知道提供者/消费者时,我如何让 Devise 只在提供者特定的命名空间上验证提供者而不是消费者? p>
这是我认为我应该做的:
controllers/provider/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 其实没什么,我只是期待一个更优雅的解决方案,也许是来自 Devise 开箱即用的功能。
-
语句'return false unless Provider.find_by(...)' 将始终返回 false 或 nil。
标签: ruby-on-rails ruby activerecord devise