我们允许用户将域添加到事件记录模型(例如 User.domain),并使用 User.find_by_domain 按域查找用户。
将来我们希望允许用户输入 *.example.com 作为他们的域,并允许 User.find_by_subdomain('sub1.example.com') 和 User.find_by_subdomain('sub2.example.com') 工作.但是,如果用户不在模型中使用像 *.example.com 这样的通配符,我们也希望 example.com 直接匹配 example.com。我们需要能够说 User.find_by_subdomain('sub1.example.com') 而不是 User.find_by_subdomain('*.example.com')
这也必须与像 sub.example.co.uk 这样的域一起工作,我们理想情况下希望可以在数据库中运行的高效查询。避免特定于数据库的查询会很好,但 Postgres 是当前的生产数据库。
提前致谢,因为我们一直在为此绞尽脑汁。
最佳答案
关于ruby-on-rails - rails : An efficient method to match subdomains in the database?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3891179/