rails-prelaunch-signup icon indicating copy to clipboard operation
rails-prelaunch-signup copied to clipboard

MailChimp API error while running migration and creating DEFAULT USERS

Open erikjosue6 opened this issue 11 years ago • 11 comments

I've been trying to run the migration for the db and theres is an error when trying to create the email address provided for the Admin by the ENV variable.

DEFAULT USERS user: Erik Santiago rake aborted! MailChimp API Error: This email address looks fake or invalid. Please enter a real email address (code -100)

I must say that I wanted to user my name and email account to create the Admin but for some reason it is not working.

erikjosue6 avatar Oct 09 '13 00:10 erikjosue6

You won't need the admin added to the MailChimp list. In user.rb, the add_user_to_mailchimp method will not be executed if the email address matches ENV['ADMIN_EMAIL'.

You may find it easier to run the migration with the default and then change it in the admin dashboard.

DanielKehoe avatar Oct 09 '13 00:10 DanielKehoe

I brought the application to the default with the only difference that I'm using gmail in development as instructed in one your tutorials. For the other part everything should be the same but still getting the error.

ROLES role: admin role: user DEFAULT USERS user: First User rake aborted! MailChimp API Error: This email address looks fake or invalid. Please enter a real email address (code -100) /Users/erikjosue6/.rvm/gems/ruby-1.9.3-p448@cemibox-prelaunch-signup/gems/gibbon-1.0.4/lib/gibbon/api_category.rb:35:in call' /Users/erikjosue6/.rvm/gems/ruby-1.9.3-p448@cemibox-prelaunch-signup/gems/gibbon-1.0.4/lib/gibbon/api_category.rb:45:inmethod_missing' /Users/erikjosue6/rails_project/cemibox-prelaunch-signup/app/models/user.rb:66:in `add_user_to_mailchimp'

and then the callbacks ...

Any suggestions?

erikjosue6 avatar Oct 09 '13 01:10 erikjosue6

Is the ADMIN_EMAIL environment variable set?

DanielKehoe avatar Oct 09 '13 02:10 DanielKehoe

Yes to [email protected].

ADMIN_NAME: First User ADMIN_EMAIL: [email protected] ADMIN_PASSWORD: changeme ROLES: [admin, user] EMAIL_ADDRESS: [email protected] DOMAIN: example.com

erikjosue6 avatar Oct 09 '13 03:10 erikjosue6

See what happens when you add log statements to the user.rb file:

  def add_user_to_mailchimp
    Rails.logger.info "step 1 value is #{ENV['ADMIN_EMAIL']}"
    return if email.include?(ENV['ADMIN_EMAIL'])
    Rails.logger.info "step 2 value is #{ENV['ADMIN_EMAIL']}"
    mailchimp = Gibbon::API.new
    result = mailchimp.lists.subscribe({
      :id => ENV['MAILCHIMP_LIST_ID'],
      :email => {:email => self.email},
      :double_optin => false,
      :update_existing => true,
      :send_welcome => true
      })
    Rails.logger.info("Subscribed #{self.email} to MailChimp") if result
  end

DanielKehoe avatar Oct 09 '13 03:10 DanielKehoe

The 2 values are as expected

step 1 value is [email protected] step 2 value is [email protected] [1m[35m (1.9ms)[0m rollback transaction

I'm sorry to bother you at this hour but haven't found any question on Stackoverflow or google or describing the error.

erikjosue6 avatar Oct 09 '13 03:10 erikjosue6

Try this:

 def add_user_to_mailchimp
    Rails.logger.info "admin email is #{ENV['ADMIN_EMAIL']}"
    Rails.logger.info "user email is #{self.email}"
    return if self.email.include?(ENV['ADMIN_EMAIL'])
    Rails.logger.info "you shouldn't see this msg if user email and admin email are the same"
    mailchimp = Gibbon::API.new
    result = mailchimp.lists.subscribe({
      :id => ENV['MAILCHIMP_LIST_ID'],
      :email => {:email => self.email},
      :double_optin => false,
      :update_existing => true,
      :send_welcome => true
      })
    Rails.logger.info("Subscribed #{self.email} to MailChimp") if result
  end

DanielKehoe avatar Oct 09 '13 03:10 DanielKehoe

I think that solved the issue since for some reason which i don't know it was taking the ADMIN_EMAIL and comparing it with the email for the second user in the seed.rb file

admin email is [email protected] user email is [email protected] you shouldn't see this msg if user email and admin email are the same

Once I erased the user2 extract the process finished.

erikjosue6 avatar Oct 09 '13 03:10 erikjosue6

Just a matter of using log statements to debug.

DanielKehoe avatar Oct 09 '13 03:10 DanielKehoe

Thank you and will do from now on.

erikjosue6 avatar Oct 09 '13 03:10 erikjosue6