2015-10-03 06:38:11 +02:00
|
|
|
class SupportersController < ApplicationController
|
2015-10-06 09:16:07 +02:00
|
|
|
before_filter :set_form_timestamp, only: :new
|
|
|
|
|
|
2015-10-03 06:38:11 +02:00
|
|
|
def new
|
|
|
|
|
@supporter = Supporter.new
|
|
|
|
|
end
|
2015-10-05 12:40:08 +02:00
|
|
|
|
|
|
|
|
def create
|
2015-11-09 10:33:26 +01:00
|
|
|
@supporter = Supporter.new supporter_form_params.merge(language: I18n.locale)
|
2015-10-06 09:16:07 +02:00
|
|
|
if !input_to_fast? && @supporter.save
|
2016-04-21 21:05:45 +02:00
|
|
|
# SupporterMailer.welcome_email(@supporter).deliver_now
|
2016-11-15 10:05:53 +01:00
|
|
|
mailchimp_registration
|
2015-10-05 12:40:08 +02:00
|
|
|
redirect_to thanks_path
|
|
|
|
|
else
|
2017-02-26 18:18:37 +01:00
|
|
|
flash.now[:danger] = input_to_fast? ? t('.timeout') : t('input_error')
|
2015-10-05 12:40:08 +02:00
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def supporter_form_params
|
2016-03-29 21:57:14 +02:00
|
|
|
params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments)
|
2015-10-05 12:40:08 +02:00
|
|
|
end
|
2016-11-15 10:05:53 +01:00
|
|
|
|
|
|
|
|
def mailchimp_registration
|
2017-03-24 18:24:42 +01:00
|
|
|
return unless Rails.env.production?
|
2016-11-15 10:05:53 +01:00
|
|
|
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
|
2015-10-03 06:38:11 +02:00
|
|
|
end
|