Automat mail chimp subscription

This commit is contained in:
2016-11-15 10:05:53 +01:00
parent ce84a2aa32
commit 42e20b6a3c
5 changed files with 27 additions and 2 deletions
+17
View File
@@ -9,6 +9,7 @@ class SupportersController < ApplicationController
@supporter = Supporter.new supporter_form_params.merge(language: I18n.locale)
if !input_to_fast? && @supporter.save
# SupporterMailer.welcome_email(@supporter).deliver_now
mailchimp_registration
redirect_to thanks_path
else
flash.now[:danger] = t '.timeout' if input_to_fast?
@@ -21,4 +22,20 @@ class SupportersController < ApplicationController
def supporter_form_params
params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments)
end
def mailchimp_registration
mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API'])
mailchimp.lists.subscribe(ENV['CH420_LIST_ID'], { 'email' => @supporter.email }, merge_vars, 'html', false)
end
def merge_vars
{ 'EMAIL' => @supporter.email,
'FNAME' => @supporter.first_name,
'LNAME' => @supporter.last_name,
'SUPPORT' => @supporter.support,
'MEMBERSHIP' => @supporter.li_membership.to_s,
'AGE' => @supporter.age_category,
'LANG' => @supporter.language,
'ZIP' => @supporter.zip }
end
end