开发者

Rails: User to Company logic based on domain name

开发者 https://www.devze.com 2023-03-08 05:20 出处:网络
I\'m working on a little web app and need some help. After a user signs up, they are assigned to a Company based on their domain name if it exists otherwise it will create a new Company with that do

I'm working on a little web app and need some help.

After a user signs up, they are assigned to a Company based on their domain name if it exists otherwise it will create a new Company with that domain.

def assign_user_to_company
 domain = email.split("@").last
 user_company = Company.find_or_create_by_domain domain
 update_attribute(:company_id, user_company.id) #or whatever you called this field
end

This is great because it groups all users into a network via their email. Yammer style. However I'm going to be listing all of these Companies and the Users within them. The problem arises when a few people sign up with google.com for example, and people in the same company register with a google.co.uk domain. This then creates separate groups of the same company.

I've been trying to think of a few ways to do this. Assigning Companies to a Group, giving a Company a parent...etc but not sure of the most efficient way of solving this proble开发者_如何学编程m.

Any help is much appreciated.


You could alias companies into a single group so one company has many domains and each domain has many users. When you want to find all the users of a company it should be simple to do.

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消