Class: SplashController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/happy_seed/splash/templates/app/controllers/splash_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



4
5
# File 'lib/generators/happy_seed/splash/templates/app/controllers/splash_controller.rb', line 4

def index
end

#signupObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/happy_seed/splash/templates/app/controllers/splash_controller.rb', line 7

def 
  if ENV['MAILCHIMP_SPLASH_SIGNUP_LIST_ID'].blank? or ENV['MAILCHIMP_API_KEY'].blank?

    @message = "The MAILCHIMP_API_KEY and MAILCHIMP_SPLASH_SIGNUP_LIST_ID environment variables need to be set for mailing list signup to work! If you don't want this feature, you can just remove the mailing list signup feature from app/views/splash/index.html.haml"

  else
    begin

      gb = Gibbon::Request.new(api_key: ENV['MAILCHIMP_API_KEY'])

     gb.lists(ENV['MAILCHIMP_SPLASH_SIGNUP_LIST_ID']).members.create(
       body: {
         email_address: params[:signup_email],
         status: "pending"
         }
       )

      @message = 'Thanks for signing up!'

    rescue StandardError => e
      @error = true

      if e.message =~ /is already subscribed to the list/
        @message = "You're already signed up to receive updates. Thanks for your enthusiasm!"
      else
        @message = "Oops! Looks like we ran into an error. How embarrassing. Please try again later!"
      end

    end
  end
end