Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #82

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

WIP #82

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gem 'rails', '6.0.4.1'
gem 'rake', '>= 10'
gem 'pg'
gem 'sprockets-rails', require: 'sprockets/railtie'
gem 'mail_form'

gem 'bootsnap'
gem 'devise'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,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)
mime-types (3.3.1)
Expand Down Expand Up @@ -336,6 +339,7 @@ DEPENDENCIES
jquery-rails
json
listen
mail_form
newrelic_rpm
nokogiri (>= 1.12.5)
oauth
Expand Down
28 changes: 17 additions & 11 deletions app/controllers/contact_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
class ContactController < ApplicationController
before_action :contact_params, only: [:create]

def index
@contact = ContactForm.new
end

def create
@contact = Contact.new(contact_params)
if @contact.invalid?
messages = @contact.errors.full_messages.to_sentence
render json: { errors: messages }, status: :unprocessable_entity
@contact = ContactForm.new(params[:contact_form])
@contact.request = request
if @contact.deliver
flash.now[:notice] = 'Your feedback has been submitted. We will reply as soon as possible.'
render :index
else
ContactMailer.contact_email(@contact).deliver
render json: { message: 'Your feedback has been submitted. We will reply as soon as possible.' }
flash.now[:error] = 'Cannot send message.'
render :index
end
end

end
private

def contact_params
params.require(:contact).permit(:email, :message, :name, :subject)
params.require(:contact_form).permit(:email, :message, :name, :subject)
end
end
end
1 change: 1 addition & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class PagesController < ApplicationController
def index
@upcoming_meetings = upcoming_meetings
@next_meeting = next_meeting
@contact = contact_params
end
end
7 changes: 7 additions & 0 deletions app/javascript/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// app/views/home/create.js.erb

// Test for ajax success
console.log("This is the create.js.erb file");
// Render flash message
$('#contact').html("<%= j render 'contact_form' %>");
$('#flash-message').html("<%= j render 'flash' %>").delay(3000).fadeOut(4000);
18 changes: 17 additions & 1 deletion app/mailers/contact_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
class ContactMailer < ActionMailer::Base
class ContactForm < MailForm::Base

default :to => "[email protected]"
attribute :name, :validate => true
attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :message
attribute :nickname, :captcha => true

def contact_email(contact)
@contact = contact
mail(:from => @contact.email, :subject => "Feedback from cincyrb.com")
end

# Declare the e-mail headers. It accepts anything the mail method
# in ActionMailer accepts.
def headers
{
:subject => "Contact Form Inquiry",
:to => "your_email@your_domain.com",
:from => %("#{name}" <#{email}>)
}
end

end
22 changes: 0 additions & 22 deletions app/models/contact.rb

This file was deleted.

26 changes: 26 additions & 0 deletions app/views/pages/_contact_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%= form_for @contact, url: pages_index_path, remote: true do |f| %>


<div>
<h2>Contact Us</h2>
<p>Have a topic idea? Want to present at a Cinci.rb meeting? Have a suggestion? Send us a comment here.</p>
<p class='flash flash_notice'></p>
<%= form_for Contact.new, url: "/pages", :remote => true do |f| %>
<div>
<div>
<%= f.text_field :name, :placeholder => "Name" %>
<%= f.text_field :email, :placeholder => "Email Address" %>
<%= f.text_field :subject, :placeholder => "Subject" %>
</div>
<div>
<%= f.text_area :message, :placeholder => "Message", :rows => 5 %>
</div>
<div>
<input type="submit" value="Submit">
</div>
</div>
<%- end %>
<div class="col-md-6" id="flash-message">
<%= render 'flash' %>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/pages/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% flash.each do |message_type, message| %>
<%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
<% end %>
15 changes: 15 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker


# config/environments/development.rb

config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors= true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: ENV["GMAIL_EMAIL"],
password: ENV["GMAIL_PASSWORD"],
authentication: 'plain',
enable_starttls_auto: true }
end
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

ActiveAdmin.routes(self)

post 'contact_us' => 'contact#create'
resources :pages, only: [:index, :new, :create]

get 'meetings' => 'meetings#index'
get 'twitter/timeline'

Expand Down
Binary file added vendor/cache/mail_form-1.9.0.gem
Binary file not shown.