mirror of
https://github.com/edcommonwealth/ecp.org.git
synced 2026-03-07 21:48:13 -08:00
Swap out contact form to one that uses mailgun
This commit is contained in:
parent
6df92d6f88
commit
7f433cf223
17 changed files with 130 additions and 70 deletions
2
Gemfile
2
Gemfile
|
|
@ -51,6 +51,8 @@ gem "bootsnap", require: false
|
|||
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
|
||||
# gem "image_processing", "~> 1.2"
|
||||
|
||||
gem 'mail_form'
|
||||
|
||||
group :development, :test do
|
||||
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
||||
gem "debug", platforms: %i[ mri mingw x64_mingw ]
|
||||
|
|
|
|||
|
|
@ -101,6 +101,9 @@ GEM
|
|||
nokogiri (>= 1.5.9)
|
||||
mail (2.7.1)
|
||||
mini_mime (>= 0.1.1)
|
||||
mail_form (1.9.0)
|
||||
actionmailer (>= 5.2)
|
||||
activemodel (>= 5.2)
|
||||
marcel (1.0.2)
|
||||
method_source (1.0.0)
|
||||
mini_mime (1.1.2)
|
||||
|
|
@ -207,6 +210,7 @@ DEPENDENCIES
|
|||
factory_bot_rails
|
||||
jbuilder
|
||||
jsbundling-rails
|
||||
mail_form
|
||||
pg (~> 1.1)
|
||||
puma (~> 5.0)
|
||||
rails (~> 7.0.4)
|
||||
|
|
|
|||
16
app/controllers/contacts_controller.rb
Normal file
16
app/controllers/contacts_controller.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class ContactsController < ApplicationController
|
||||
def new
|
||||
@contact = Contact.new
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = Contact.new(params[:contact])
|
||||
@contact.request = request
|
||||
if @contact.deliver
|
||||
flash.now[:success] = 'Message sent!'
|
||||
else
|
||||
flash.now[:error] = 'Could not send message'
|
||||
render :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,2 +1,5 @@
|
|||
class HomeController < ApplicationController
|
||||
def index
|
||||
@contact = Contact.new
|
||||
end
|
||||
end
|
||||
|
|
|
|||
2
app/helpers/contact_helper.rb
Normal file
2
app/helpers/contact_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module ContactHelper
|
||||
end
|
||||
2
app/helpers/contacts_helper.rb
Normal file
2
app/helpers/contacts_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module ContactsHelper
|
||||
end
|
||||
17
app/models/contact.rb
Normal file
17
app/models/contact.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class Contact < MailForm::Base
|
||||
attribute :name, validate: true
|
||||
attribute :email, validate: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
|
||||
attribute :organization
|
||||
attribute :message
|
||||
attribute :nickname, captcha: true
|
||||
|
||||
# Declare the e-mail headers. It accepts anything the mail method
|
||||
# in ActionMailer accepts.
|
||||
def headers
|
||||
{
|
||||
:subject => "Contact Form Inquiry",
|
||||
:to => ENV['CONTACT_FORM_DESTINATION'] || "memoryman51@hotmail.com",
|
||||
:from => %("#{name}" <#{email}>)
|
||||
}
|
||||
end
|
||||
end
|
||||
26
app/views/contacts/_new.html.erb
Normal file
26
app/views/contacts/_new.html.erb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<div class="container pb-5">
|
||||
<h1>Contact Form</h1>
|
||||
<%= form_for @contact do |f| %>
|
||||
<div class="col-md-6">
|
||||
<%= f.label :name %></br>
|
||||
<%= f.text_field :name, required: true, class: "contact-form-text-area" %></br>
|
||||
|
||||
<%= f.label :email %></br>
|
||||
<%= f.text_field :email, required: true, class: "contact-form-text-area" %></br>
|
||||
|
||||
<%= f.label :organization %></br>
|
||||
<%= f.text_field :organization, required: true, class: "contact-form-text-area" %></br>
|
||||
|
||||
<%= f.label :message %></br>
|
||||
<%= f.text_area :message, rows: 8, cols: 40, required: true, class: "contact-form-text-area",
|
||||
placeholder: "Send me a message"%></br>
|
||||
|
||||
<div class= "d-none">
|
||||
<%= f.label :nickname %>
|
||||
<%= f.text_field :nickname, :hint => 'Leave this field blank!' %>
|
||||
</div>
|
||||
|
||||
<%= f.submit 'Send Message', class: 'btn btn-primary' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
5
app/views/contacts/create.html.erb
Normal file
5
app/views/contacts/create.html.erb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<div class="container">
|
||||
<h1>Contact Form</h1>
|
||||
|
||||
<h3>Thank you for your message!</h3>
|
||||
</div>
|
||||
1
app/views/contacts/new.html.erb
Normal file
1
app/views/contacts/new.html.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
<%= render(partial: "new") %>
|
||||
|
|
@ -13,6 +13,8 @@
|
|||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<!-- Features section-->
|
||||
<section class="py-5 border-bottom" id="features">
|
||||
<div class="container px-5 my-5">
|
||||
|
|
@ -33,71 +35,9 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Contact section-->
|
||||
<section class="bg-light py-5">
|
||||
<div class="container px-5 my-5 px-5">
|
||||
<div class="text-center mb-5">
|
||||
<div class="feature bg-primary bg-gradient text-white rounded-3 mb-3"><i class="bi bi-envelope"></i></div>
|
||||
<h2 class="fw-bolder">Get in touch</h2>
|
||||
<p class="lead mb-0">We'd love to hear from you</p>
|
||||
</div>
|
||||
<div class="row gx-5 justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<!-- * * * * * * * * * * * * * * *-->
|
||||
<!-- * * SB Forms Contact Form * *-->
|
||||
<!-- * * * * * * * * * * * * * * *-->
|
||||
<!-- This form is pre-integrated with SB Forms.-->
|
||||
<!-- To make this form functional, sign up at-->
|
||||
<!-- https://startbootstrap.com/solution/contact-forms-->
|
||||
<!-- to get an API token!-->
|
||||
<form id="contactForm" data-sb-form-api-token="8495ab6d-c9ab-43f4-9e22-4203c4481357">
|
||||
<!-- Name input-->
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="name" type="text" placeholder="Enter your name..." data-sb-validations="required" />
|
||||
<label for="name">Full name</label>
|
||||
<div class="invalid-feedback" data-sb-feedback="name:required">A name is required.</div>
|
||||
</div>
|
||||
<!-- Email address input-->
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="email" type="email" placeholder="name@example.com" data-sb-validations="required,email" />
|
||||
<label for="email">Email address</label>
|
||||
<div class="invalid-feedback" data-sb-feedback="email:required">An email is required.</div>
|
||||
<div class="invalid-feedback" data-sb-feedback="email:email">Email is not valid.</div>
|
||||
</div>
|
||||
<!-- Phone number input-->
|
||||
<div class="form-floating mb-3">
|
||||
<input class="form-control" id="phone" type="tel" placeholder="(123) 456-7890" data-sb-validations="required" />
|
||||
<label for="phone">Phone number</label>
|
||||
<div class="invalid-feedback" data-sb-feedback="phone:required">A phone number is required.</div>
|
||||
</div>
|
||||
<!-- Message input-->
|
||||
<div class="form-floating mb-3">
|
||||
<textarea class="form-control" id="message" type="text" placeholder="Enter your message here..." style="height: 10rem" data-sb-validations="required"></textarea>
|
||||
<label for="message">Message</label>
|
||||
<div class="invalid-feedback" data-sb-feedback="message:required">A message is required.</div>
|
||||
</div>
|
||||
<!-- Submit success message-->
|
||||
<!---->
|
||||
<!-- This is what your users will see when the form-->
|
||||
<!-- has successfully submitted-->
|
||||
<div class="d-none" id="submitSuccessMessage">
|
||||
<div class="text-center mb-3">
|
||||
<div class="fw-bolder">Form submission successful!</div>
|
||||
To activate this form, sign up at
|
||||
<br />
|
||||
<a href="https://startbootstrap.com/solution/contact-forms">https://startbootstrap.com/solution/contact-forms</a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Submit error message-->
|
||||
<!---->
|
||||
<!-- This is what your users will see when there is-->
|
||||
<!-- an error submitting the form-->
|
||||
<div class="d-none" id="submitErrorMessage"><div class="text-center text-danger mb-3">Error sending message!</div></div>
|
||||
<!-- Submit Button-->
|
||||
<div class="d-grid"><button class="btn btn-primary btn-lg disabled" id="submitButton" type="submit">Submit</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Message confirmation-->
|
||||
<%= render partial: 'layouts/message_confirmation' %>
|
||||
|
||||
<!-- Contact section-->
|
||||
<%# <%= link_to "Contact Form", new_contact_path %1> %>
|
||||
<%= render partial: "contacts/new" %>
|
||||
|
|
|
|||
6
app/views/layouts/_message_confirmation.html.erb
Normal file
6
app/views/layouts/_message_confirmation.html.erb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<div class="container">
|
||||
<br>
|
||||
<% flash.each do |key, message| %>
|
||||
<p class="alert alert-<%= key %>"><%= message %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
<body>
|
||||
<%= render partial: 'layouts/nav' %>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
<!-- Footer-->
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require "active_support/core_ext/integer/time"
|
||||
require 'active_support/core_ext/integer/time'
|
||||
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
|
@ -19,13 +19,13 @@ Rails.application.configure do
|
|||
|
||||
# Enable/disable caching. By default caching is disabled.
|
||||
# Run rails dev:cache to toggle caching.
|
||||
if Rails.root.join("tmp/caching-dev.txt").exist?
|
||||
if Rails.root.join('tmp/caching-dev.txt').exist?
|
||||
config.action_controller.perform_caching = true
|
||||
config.action_controller.enable_fragment_cache_logging = true
|
||||
|
||||
config.cache_store = :memory_store
|
||||
config.public_file_server.headers = {
|
||||
"Cache-Control" => "public, max-age=#{2.days.to_i}"
|
||||
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
||||
}
|
||||
else
|
||||
config.action_controller.perform_caching = false
|
||||
|
|
@ -36,6 +36,12 @@ Rails.application.configure do
|
|||
# Store uploaded files on the local file system (see config/storage.yml for options).
|
||||
config.active_storage.service = :local
|
||||
|
||||
# Local actionmailer delivery method
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
|
||||
# Local actionmailer smpt address and port
|
||||
config.action_mailer.smtp_settings = { address: '127.0.0.1', port: 1025 }
|
||||
|
||||
# Don't care if the mailer can't send.
|
||||
config.action_mailer.raise_delivery_errors = false
|
||||
|
||||
|
|
|
|||
|
|
@ -90,4 +90,14 @@ Rails.application.configure do
|
|||
|
||||
# Do not dump schema after migrations.
|
||||
config.active_record.dump_schema_after_migration = false
|
||||
|
||||
ActionMailer::Base.smtp_settings = {
|
||||
:port => ENV['MAILGUN_SMTP_PORT'],
|
||||
:address => ENV['MAILGUN_SMTP_SERVER'],
|
||||
:user_name => ENV['MAILGUN_SMTP_LOGIN'],
|
||||
:password => ENV['MAILGUN_SMTP_PASSWORD'],
|
||||
:domain => 'edcommonwealth.org', # UPDATE THIS VALUE WITH YOUR OWN APP
|
||||
:authentication => :plain,
|
||||
}
|
||||
ActionMailer::Base.delivery_method = :smtp
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,5 +9,7 @@ Rails.application.routes.draw do
|
|||
resources :construction, only: :index
|
||||
resources :district_leader, only: :index
|
||||
|
||||
resources :contacts, only: %i[new create]
|
||||
|
||||
root 'home#index'
|
||||
end
|
||||
|
|
|
|||
17
db/schema.rb
generated
Normal file
17
db/schema.rb
generated
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# This file is the source Rails uses to define your schema when running `bin/rails
|
||||
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
||||
# be faster and is potentially less error prone than running all of your
|
||||
# migrations from scratch. Old migrations may fail to apply correctly if those
|
||||
# migrations use external dependencies or application code.
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 0) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue