Skip to content

Commit

Permalink
Configure app to send survey and handle unsubscribes
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli Fatsi committed Aug 6, 2020
1 parent 8def7eb commit 7465d10
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 4 deletions.
23 changes: 23 additions & 0 deletions app/controllers/unsubscribes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class UnsubscribesController < ApplicationController
def new
end

def create
if unsubscribe_email.present?
if user = User.find_by(email: unsubscribe_email)
user.update(can_be_emailed: false)
end

render :success
else
render :new
end
end

private

def unsubscribe_email
params[:unsubscribe][:email]
end
helper_method :unsubscribe_email
end
16 changes: 16 additions & 0 deletions app/javascript/src/css/default/Button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.btn {
background-color: #404458;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 3px;
}

.btn:hover {
background-color: #525670;
cursor: pointer;
}
3 changes: 2 additions & 1 deletion app/javascript/src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import './reset.css';
@import './css/default/AdventureHeader.css';
@import './css/default/Badge.css';
@import './css/default/Button.css';
@import './css/default/Brand.css';
@import './css/default/Footer.css';

Expand All @@ -23,7 +24,7 @@ main {

.screenreader-only {
border: 0;
clip: rect(0,0,0,0);
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: '[email protected].com'
layout 'mailer'
end
9 changes: 9 additions & 0 deletions app/mailers/survey_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SurveyMailer < ApplicationMailer
default from: "Storyboard Team <[email protected]>"

def initial_feedback(user)
@user = user

mail(to: user.email, subject: "Storyboard User Survey")
end
end
36 changes: 36 additions & 0 deletions app/views/survey_mailer/initial_feedback.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<p>
Hello,
</p>

<p>
Storyboard is conducting an online survey to gather user feedback and to learn more about how people use Storyboard. Your input would be incredibly helpful, and be used to inform the future of Storyboard.
</p>

<p>
All respondents who complete the survey will be entered in a drawing to win a $20 Amazon.com gift card.
</p>

<p>
It should take 5-10 minutes to complete. You may access the survey using the link below.
</p>

<p>
<%= link_to "https://www.surveygizmo.com/s3/5759951/Storyboard-User-Survey", "https://www.surveygizmo.com/s3/5759951/Storyboard-User-Survey" %>
</p>

<p>
If you have any questions, you can contact Laura Sweltz at [email protected].
</p>

<p>
Thank you,
<br>
Storyboard Team
</p>

<br>
<hr>

<p>
Don’t want to hear from us again? <%= link_to "Unsubscribe here", new_unsubscribe_url(email: @user.email) %>.
</p>
17 changes: 17 additions & 0 deletions app/views/survey_mailer/initial_feedback.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Hello,

Storyboard is conducting an online survey to gather user feedback and to learn more about how people use Storyboard. Your input would be incredibly helpful.

All respondents who complete the survey will be entered in a drawing to win a $20 Amazon.com gift card.

It should take 5-10 minutes to complete. You may access the survey using the link below.

https://www.surveygizmo.com/s3/5759951/Storyboard-User-Survey

If you have any questions, you can contact Laura Sweltz at [email protected].

Thank you,
Storyboard Team

================================================================
Don’t want to hear from us again? Unsubscribe here: <%= new_unsubscribe_url(email: @user.email) %>.
10 changes: 10 additions & 0 deletions app/views/unsubscribes/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="AccountForm Container">
<%= form_for :unsubscribe, url: unsubscribes_path do |f| %>
<div class="Field">
<%= f.label :email %>
<%= f.email_field :email, value: params[:email] %>
</div>

<%= f.submit "Unsubscribe", class: "btn" %>
<% end %>
</div>
5 changes: 5 additions & 0 deletions app/views/unsubscribes/success.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="Container">
<p>
We've removed <%= unsubscribe_email %> from our mailing list. Fare thee well.
</p>
</div>
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2

config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
Expand Down
5 changes: 4 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
default: &default
adapter: postgresql
encoding: unicode
host: db

# Uncomment this line if you're running in Docker
# host: db

# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
post "/api/:id", to: "api/adventures#update"
get "/api/:id", to: "api/adventures#show"

get "unsubscribe", to: "unsubscribes#new", as: :new_unsubscribe
resources :unsubscribes, only: [:create]

# Keep this block at the bottom so the "/:id adventures#show"
# doesn't catch other routes
resources :adventures, path: "/" do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200806131054_add_can_be_emailed_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCanBeEmailedToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :can_be_emailed, :boolean, default: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_05_27_151913) do
ActiveRecord::Schema.define(version: 2020_08_06_131054) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -54,6 +54,7 @@
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "can_be_emailed", default: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Expand Down
5 changes: 5 additions & 0 deletions lib/mailer_previews/survey_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SurveyMailerPreview < ActionMailer::Preview
def initial_feedback
SurveyMailer.initial_feedback(User.first)
end
end

0 comments on commit 7465d10

Please sign in to comment.