diff --git a/Gemfile b/Gemfile
index a393b3c..0ddfd60 100644
--- a/Gemfile
+++ b/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 ]
diff --git a/Gemfile.lock b/Gemfile.lock
index d26295b..6d862f0 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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)
diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb
new file mode 100644
index 0000000..4fb58af
--- /dev/null
+++ b/app/controllers/contacts_controller.rb
@@ -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
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index fc0b474..ff3df1a 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,2 +1,5 @@
class HomeController < ApplicationController
+ def index
+ @contact = Contact.new
+ end
end
diff --git a/app/helpers/contact_helper.rb b/app/helpers/contact_helper.rb
new file mode 100644
index 0000000..83d146d
--- /dev/null
+++ b/app/helpers/contact_helper.rb
@@ -0,0 +1,2 @@
+module ContactHelper
+end
diff --git a/app/helpers/contacts_helper.rb b/app/helpers/contacts_helper.rb
new file mode 100644
index 0000000..593025b
--- /dev/null
+++ b/app/helpers/contacts_helper.rb
@@ -0,0 +1,2 @@
+module ContactsHelper
+end
diff --git a/app/models/contact.rb b/app/models/contact.rb
new file mode 100644
index 0000000..c507a33
--- /dev/null
+++ b/app/models/contact.rb
@@ -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
diff --git a/app/views/contacts/_new.html.erb b/app/views/contacts/_new.html.erb
new file mode 100644
index 0000000..4dc9b6e
--- /dev/null
+++ b/app/views/contacts/_new.html.erb
@@ -0,0 +1,26 @@
+
+
Contact Form
+ <%= form_for @contact do |f| %>
+
+ <%= f.label :name %>
+ <%= f.text_field :name, required: true, class: "contact-form-text-area" %>
+
+ <%= f.label :email %>
+ <%= f.text_field :email, required: true, class: "contact-form-text-area" %>
+
+ <%= f.label :organization %>
+ <%= f.text_field :organization, required: true, class: "contact-form-text-area" %>
+
+ <%= f.label :message %>
+ <%= f.text_area :message, rows: 8, cols: 40, required: true, class: "contact-form-text-area",
+ placeholder: "Send me a message"%>
+
+
+ <%= f.label :nickname %>
+ <%= f.text_field :nickname, :hint => 'Leave this field blank!' %>
+
+
+ <%= f.submit 'Send Message', class: 'btn btn-primary' %>
+
+ <% end %>
+
diff --git a/app/views/contacts/create.html.erb b/app/views/contacts/create.html.erb
new file mode 100644
index 0000000..c3d5fcd
--- /dev/null
+++ b/app/views/contacts/create.html.erb
@@ -0,0 +1,5 @@
+
+
Contact Form
+
+ Thank you for your message!
+
diff --git a/app/views/contacts/new.html.erb b/app/views/contacts/new.html.erb
new file mode 100644
index 0000000..c2f71f8
--- /dev/null
+++ b/app/views/contacts/new.html.erb
@@ -0,0 +1 @@
+<%= render(partial: "new") %>
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index c076930..4a4c905 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -13,6 +13,8 @@
+
+
-
-
-
-
-
-
Get in touch
-
We'd love to hear from you
-
-
-
-
+
+<%= render partial: 'layouts/message_confirmation' %>
+
+<%# <%= link_to "Contact Form", new_contact_path %1> %>
+<%= render partial: "contacts/new" %>
diff --git a/app/views/layouts/_message_confirmation.html.erb b/app/views/layouts/_message_confirmation.html.erb
new file mode 100644
index 0000000..7f8ebc9
--- /dev/null
+++ b/app/views/layouts/_message_confirmation.html.erb
@@ -0,0 +1,6 @@
+
+
+ <% flash.each do |key, message| %>
+
<%= message %>
+ <% end %>
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 9f1935c..99c0eae 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -13,6 +13,7 @@
<%= render partial: 'layouts/nav' %>
+
<%= yield %>
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 8500f45..9f4c8bd 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -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
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 524c428..e1425b5 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 2b94b59..99cf864 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000..b783f98
--- /dev/null
+++ b/db/schema.rb
@@ -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