Automat mail chimp subscription
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -4,7 +4,7 @@ class Supporter
|
||||
include Mongoid::Paranoia
|
||||
include Geocoder::Model::Mongoid
|
||||
|
||||
COUNTER_START = 10003
|
||||
COUNTER_START = 10_003
|
||||
|
||||
geocoded_by :address
|
||||
after_validation :geocode # auto-fetch coordinates
|
||||
|
||||
Reference in New Issue
Block a user