-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c98bc7
commit 654d594
Showing
5 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
class VisitorsController < ApplicationController | ||
|
||
def new | ||
@owner = Owner.new | ||
end | ||
def new | ||
@visitor = Visitor.new | ||
end | ||
|
||
def create | ||
@visitor = Visitor.new(secure_params) | ||
if @visitor.valid? | ||
@visitor.subscribe | ||
flash[:notice] = "Signed up #{@visitor.email}." | ||
redirect_to root_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def secure_params | ||
params.require(:visitor).permit(:email) | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Visitor < ActiveRecord::Base | ||
has_no_table | ||
column :email, :string | ||
validates_presence_of :email | ||
validates_format_of :email, :with => /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i | ||
|
||
def subscribe | ||
mailchimp = Gibbon::API.new(Rails.application.secrets.mailchimp_api_key) | ||
result = mailchimp.lists.subscribe({ | ||
:id => Rails.application.secrets.mailchimp_list_id, | ||
:email => {:email => self.email}, | ||
:double_optin => false, | ||
:update_existing => true, | ||
:send_welcome => true | ||
}) | ||
Rails.logger.info("Subscribed #{self.email} to MailChimp") if result | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<h3>Home</h3> | ||
<p>Welcome to the home of <%= @owner.name %>.</p> | ||
<p>I was born on <%= @owner.birthdate %>.</p> | ||
<p>Only <%= @owner.countdown %> days until my birthday!</p> | ||
|
||
<% content_for :title do %>Foobar Kadigan<% end %> | ||
<% content_for :description do %>Website of Foobar Kadigan<% end %> | ||
<section> | ||
<img src="https://lorempixel.com/1170/600/cats/1"> | ||
</section> | ||
<section> | ||
<div class="column"> | ||
<h2>Stay in touch.</h2> | ||
</div> | ||
<div class="column"> | ||
<div class="form-centered"> | ||
<%= simple_form_for @visitor do |f| %> | ||
<%= f.error_notification %> | ||
<%= f.input :email, label: false, :placeholder => 'Your email address...' %> | ||
<br/> | ||
<%= f.button :submit, "Sign up for the newsletter", :class => "submit" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Rails.application.routes.draw do | ||
resources :contacts, only: [:new, :create] | ||
resources :visitors, only: [:new, :create] | ||
root to: 'visitors#new' | ||
end |