This last week I finally sat down and scratched an itch that has been bothering me for some time.
Sometimes when preparing large batches of data we knead the data ahead of, can trust that it's valid based on where it came from, or have DB-level constraints that enforce validations.
When we do we don't need to run Active Record validations during the import.
MAILCHIMP-LIST-ID = "xxxxxxxxxx" Now the time is to get to know how to use mailchimp-api gem Following line will create the object of mailchimp, we will access the mailchimp-api method using this object.
for further information of this method you can have look here Example for this method is not even given in mailchimp-api sample project. Mailchimp Api provides you a method using which you can simply pass the hash of data and in single call all of your subscribers will be added at mailchimp.
Over the years activerecord-import has become the defacto standard for efficiently importing large batches of data with Active Record.
It has been maintained by an awesome community of contributors. Plus, if you're using any Active Record adapter(s) compatible with these databases – e.g.The job that took several hours now took under two minutes.That library today is known as the activerecord-import and its available as a rubygem.Now there are multiple things that you can do from mailchimp-api. Now create the List at mailchimp and get the list Id.Add it in your constants, where you mentioned the API-KEY.That is a lot of stuff for the database to do and it takes an enormous amount of time to do it all. Instead of using # convert_csv_to_books is a method that converts CSV into an # array of Book models, returning an array of attributes books = convert_csv_to_book_do |attrs| Book.new(attrs) end Book.import books One thing to note: validations like uniqueness that check against the database by issuing SELECT queries will not know about duplicates in your dataset.