when I create a new user, to avoid duplicates, I use the find_or_initialize method:
user = find_or_initialize_by_email(the_email)
If this user is created with a related company, how can I avoid the duplicates in companies?
Can I do something like:
find_or_initialize_by_email_and_by_company_name(the_email, the_company_name)
Thanks!
Rails 3.2 way is
User.where(email: the_email, company_name: the_company_name).first_or_initialize
Using
find_or_initialize_by_email_and_company_name(the_email, the_company_name)
you will create users uniq both by email and company name. (by is used only once)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With