Class: CMS::MailchimpController

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/cms/mailchimp_controller.rb

Instance Method Summary collapse

Instance Method Details

#subscribeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/cms/mailchimp_controller.rb', line 5

def subscribe
  respond_to do |format|
    format.js do
      begin
        gb = Gibbon::API.new(Rails.application.secrets.mailchimp_api_key, { timeout: 15 })
        gb.lists.subscribe(
          id: Rails.application.secrets.send(:"mailchimp_list_id_#{I18n.locale}"),
          email: { email: params[:mailchimp][:email] },
          double_optin: false
        )
        flash_now!(:success)
      rescue Gibbon::MailChimpError => exception
        cms_logger exception, 'mailchimp'
        flash_now!(:error)
      end
    end
  end
end