I'm using the gem called omnicontacts that allow me to export my gmail contacts. When I've retrieved my contacts I'd like to save them into a table called contacts.
However I receive the array of emails, then I have to go through each of them in a loop and print out their email. Now I'm wondering how I can save all of them (each email as it's own). Technically I guess I could loop through a create function but that would take up an insane amount of time.
What's the best practice when it comes to receiving an array, then looping through each of them to save them?
Currently I do this in my view:
<h1>Your Contacts</h1>
<div class="list-group">
<% @contacts.each do |contact| %>
<div class="list-group-item">
<div class="media">
<div class="media-left">
<%= image_tag avatar_url(contact[:email].to_s), height: '50', width: '50', alt: "#{contact[:name]}", class: 'img-rounded img-object' %>
</div>
<div class="media-body">
<h4 class="list-group-item-heading media-heading"><%= contact[:name].titleize %></h4>
<p class="list-group-item-text text-muted"><%= contact[:email] %> </p>
</div>
</div>
</div>
<% end %>
</div>
My controller looks like this:
def create
@imported_contacts = request.env['omnicontacts.contacts']
@user = request.env['omnicontacts.user']
end
@contactsarray, you don't have to create new contacts, you just have to update theiremailattribute in the database as shown in my answer below.