2012-04-24 66 views
1

我对应用程序使用Basecamp风格的子域名。使用设计,我可以让用户通过使用User.rb以下仅访问他们的子域名:设计,子域名和超级用户

def self.find_for_authentication(conditions={}) 
    conditions[:account_id] = Account.find_by_subdomain(conditions.delete(:subdomain)).id 
    super(conditions) 
    end 

此检查,以确保与用户尝试登录相关帐户的子域匹配。它工作正常。

我的问题是,我想允许超级用户登录太...谁不会有一个关联的'帐户'。他们反而会产生“超级用户”布尔列在同一个‘用户’模式。

有没有一种方法来检查正确的子域或‘超级用户’状态?

谢谢!

回答

0

如果你为所有的超级用户开立账户,我不知道这个被称为什么阶段的Auth过程,但也许是沿着这些线路的东西..?

def self.find_for_authentication(conditions={}) 
    if subdomain = conditions.delete(:subdomain) 
    conditions[:account_id] = Account.find_by_subdomain(subdomain).id 
    elsif User.where(conditions).where(:superuser => true).length > 0 
    conditions[:account_id] = 1 # 1 is account reserved for super users 
    end 

    super(conditions) 
en