I am developing a Rails 3 application (which acts as an API) and I allow
people to send in a bunch of email address (via an iPhone app) and then automatically
search the database for matching members (through emails).
It is working now (below code) but is returning doubles if the user sends in more than one copy of each email.
@users = @emails.find_all {|profile| User.find_by_email(profile['email']) }
I want the api to only return one unique copy of the user if found.
I tried the below code but it does not work.
@users = @emails.find_all {|profile| User.select('DISTINCT email').where("LOWER (email) = ?", "%#{profile['email']}%") }
How can the first line of code above be changed to distinct lookups?
Thankful for all input!
I would take a look at
How do I get the unique elements from an array of hashes in Ruby?
Seems like to be what you need!