Topic: How do I do a parse, lookup, and assign foreign key on a signup page?

Hi, needing some help to just break down the problem.

I have new users who will put in User.Email in a signup process. (I am using Ruby on Rails).

For any given email, I want to parse out the @domain portion.

I then want to find in a different model, Companies, the company_id with the matching column for @domain.

I want to return that instance, and then pass that value into the User.new

I kind of get what needs to happen at the level described, but need some guidance on the next level down.

Re: How do I do a parse, lookup, and assign foreign key on a signup page?

Something like this may help ...

def create
  ...
  user = User.new(params[:user])
  domain = user.email.split("@")[1] # domain is everything after the @
  company = Company.find_by_domain(domain)
  user.company = company if company
  if user.save 
    ...
  end
end