From 625f6d97f9e899c7d12a2aec20b0fe32ba1bf5f0 Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Sat, 27 Oct 2018 22:02:49 +0530 Subject: [PATCH 1/9] Remove contact form entry in dp, create email trigger functionality and add figaro for ENV variables --- Gemfile | 3 +++ Gemfile.lock | 5 +++- app/assets/javascripts/site.js | 6 ++--- app/controllers/contacts_controller.rb | 11 ++++++++ app/controllers/subscribe_users_controller.rb | 26 ------------------- app/mailers/application_mailer.rb | 2 +- app/mailers/contact_mailer.rb | 7 +++++ app/models/subscribe_user.rb | 10 ------- app/views/application/_footer.html.erb | 6 ++--- .../contact_mailer/contact_send.html.erb | 19 ++++++++++++++ app/views/sites/pages/_contact_us.html.erb | 6 ++--- config/database.yml | 12 ++++++--- config/environments/development.rb | 16 ++++++++++++ config/environments/production.rb | 19 +++++++++++++- config/routes.rb | 2 +- .../20180404232602_create_subscribe_users.rb | 13 ---------- db/schema.rb | 11 +------- test/mailers/contact_mailer_test.rb | 7 +++++ .../previews/contact_mailer_preview.rb | 4 +++ 19 files changed, 110 insertions(+), 75 deletions(-) create mode 100644 app/controllers/contacts_controller.rb delete mode 100644 app/controllers/subscribe_users_controller.rb create mode 100644 app/mailers/contact_mailer.rb delete mode 100644 app/models/subscribe_user.rb create mode 100644 app/views/contact_mailer/contact_send.html.erb delete mode 100644 db/migrate/20180404232602_create_subscribe_users.rb create mode 100644 test/mailers/contact_mailer_test.rb create mode 100644 test/mailers/previews/contact_mailer_preview.rb diff --git a/Gemfile b/Gemfile index 502cba1..91c54c4 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,9 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +## For env variables +gem 'figaro' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 35ce7e7..f5eb857 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,8 @@ GEM erubi (1.7.1) execjs (2.7.0) ffi (1.9.23) + figaro (1.1.1) + thor (~> 0.14) globalid (0.4.1) activesupport (>= 4.2.0) i18n (1.0.0) @@ -178,6 +180,7 @@ DEPENDENCIES byebug capybara (~> 2.13) coffee-rails (~> 4.2) + figaro jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) @@ -193,4 +196,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 1.16.1 + 1.16.2 diff --git a/app/assets/javascripts/site.js b/app/assets/javascripts/site.js index c22b599..e285353 100644 --- a/app/assets/javascripts/site.js +++ b/app/assets/javascripts/site.js @@ -1,5 +1,5 @@ $(function(){ - $(document).on('click', "#subscribe-user", function(e){ + $(document).on('click', "#contact_user", function(e){ e.preventDefault(); var self = $(this); @@ -8,7 +8,7 @@ $(function(){ url: self.data('url'), dataType: 'JSON', data: { - subscribe_user: { + contact: { first_name: $("#first_name").val(), last_name: $("#last_name").val(), email: $("#email").val(), @@ -24,4 +24,4 @@ $(function(){ console.log("==data", data) }) }) -}) \ No newline at end of file +}) diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb new file mode 100644 index 0000000..8266e00 --- /dev/null +++ b/app/controllers/contacts_controller.rb @@ -0,0 +1,11 @@ +class ContactsController < ApplicationController + def create + ContactMailer.contact_send(contact_params).deliver + end + + private + + def contact_params + params.require(:contact).permit(:first_name, :last_name, :email) + end +end diff --git a/app/controllers/subscribe_users_controller.rb b/app/controllers/subscribe_users_controller.rb deleted file mode 100644 index 9ba0b62..0000000 --- a/app/controllers/subscribe_users_controller.rb +++ /dev/null @@ -1,26 +0,0 @@ -class SubscribeUsersController < ApplicationController - - def create - build_subscribe_user - respond_to do |format| - format.json { render json: { is_success: @subscribe_user.save! } } - end - end - - private - - def subscribe_user_params - params.fetch(:subscribe_user, {}) - .permit(:first_name, :last_name, :email) - end - - def build_subscribe_user - @subscribe_user ||= subscribe_user_scope - @subscribe_user.attributes = subscribe_user_params - end - - def subscribe_user_scope - @subscribe_user = SubscribeUser.new - end - -end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..774d0d9 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' + default from: ENV['FROM_EMAIL'] layout 'mailer' end diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb new file mode 100644 index 0000000..9f81428 --- /dev/null +++ b/app/mailers/contact_mailer.rb @@ -0,0 +1,7 @@ +class ContactMailer < ApplicationMailer + + def contact_send(contact) + @contact = contact + mail(to: ENV['TO_EMAILS'], subject: 'Contact') + end +end diff --git a/app/models/subscribe_user.rb b/app/models/subscribe_user.rb deleted file mode 100644 index a732548..0000000 --- a/app/models/subscribe_user.rb +++ /dev/null @@ -1,10 +0,0 @@ -class SubscribeUser < ApplicationRecord - EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i - - validates :email, presence: true, uniqueness: true - validates_format_of :email, :with => EMAIL_REGEX, :on => :create - - scope :active, -> { where(status: 'A') } - - has_many :page_stats, as: :page_stateable -end diff --git a/app/views/application/_footer.html.erb b/app/views/application/_footer.html.erb index 0fb19ce..297dfb7 100644 --- a/app/views/application/_footer.html.erb +++ b/app/views/application/_footer.html.erb @@ -11,7 +11,7 @@
- <%= form_tag(subscribe_users_path,class: 'contact-form form-black') do %> + <%= form_tag(contacts_path, class: 'contact-form form-black') do %>
<%= text_field_tag :first_name, nil, class: 'contact-form-name', placeholder: 'First Name...', required: true %> @@ -42,7 +42,7 @@ <% end %>
- @@ -98,4 +98,4 @@
- \ No newline at end of file + diff --git a/app/views/contact_mailer/contact_send.html.erb b/app/views/contact_mailer/contact_send.html.erb new file mode 100644 index 0000000..5091220 --- /dev/null +++ b/app/views/contact_mailer/contact_send.html.erb @@ -0,0 +1,19 @@ + + + + + + +

Welcome to Bushido Lab

+

+ <%= @contact[:first_name] %> +

+

+ <%= @contact[:last_name] %> +

+

+ <%= @contact[:email] %> +

+

Thanks for joining and have a great day!

+ + diff --git a/app/views/sites/pages/_contact_us.html.erb b/app/views/sites/pages/_contact_us.html.erb index 32a2de9..ac1adab 100644 --- a/app/views/sites/pages/_contact_us.html.erb +++ b/app/views/sites/pages/_contact_us.html.erb @@ -102,7 +102,7 @@
- <%= form_tag(subscribe_users_path), class: 'contact-form form-black' do %> + <%= form_tag(contacts_path), class: 'contact-form form-black' do %>
<%= text_field_tag :first_name, nil, class: 'contact-form-name', placeholder: 'First Name...', required: true %> @@ -124,7 +124,7 @@ <% end %>
- @@ -167,4 +167,4 @@ - adapter: postgresql encoding: unicode - # For details on connection pooling, see Rails configuration guide - # http://guides.rubyonrails.org/configuring.html#database-pooling - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + pool: 5 + username: admin_user + password: root + host: localhost development: <<: *default diff --git a/config/environments/development.rb b/config/environments/development.rb index 5187e22..f8e25cd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -51,4 +51,20 @@ # 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 + + ## SMTP Credentials + config.action_mailer.default_url_options = { host: ENV['HOST'] } + config.action_mailer.delivery_method = :smtp + + config.action_mailer.smtp_settings = { + address: ENV['SMTP_ADDRESS'], + port: ENV['SMTP_PORT'], + domain: ENV['SMTP_DOMAIN'], + user_name: ENV['SMTP_USER_NAME'], + password: ENV['SMTP_PASSWORD'], + authentication: :plain, + ssl: true, + tls: true, + enable_starttls_auto: true + } end diff --git a/config/environments/production.rb b/config/environments/production.rb index 54ecbae..882e866 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -64,7 +64,7 @@ # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). @@ -86,6 +86,23 @@ config.logger = ActiveSupport::TaggedLogging.new(logger) end + ## SMTP Credentials + config.action_mailer.perform_deliveries = true + config.action_mailer.default_url_options = { host: ENV['HOST'] } + config.action_mailer.delivery_method = :smtp + + config.action_mailer.smtp_settings = { + address: ENV['SMTP_ADDRESS'], + port: ENV['SMTP_PORT'], + domain: ENV['SMTP_DOMAIN'], + user_name: ENV['SMTP_USER_NAME'], + password: ENV['SMTP_PASSWORD'], + authentication: :plain, + ssl: true, + tls: true, + enable_starttls_auto: true + } + # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end diff --git a/config/routes.rb b/config/routes.rb index 9611d20..3bd8fc5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do root "sites#show" - resources :subscribe_users, only: [:create] + resources :contacts, only: :create get "/:slug", to: "sites#show" end diff --git a/db/migrate/20180404232602_create_subscribe_users.rb b/db/migrate/20180404232602_create_subscribe_users.rb deleted file mode 100644 index cf91c4a..0000000 --- a/db/migrate/20180404232602_create_subscribe_users.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateSubscribeUsers < ActiveRecord::Migration[5.1] - def change - create_table :subscribe_users do |t| - t.string :first_name, limit: 100 - t.string :last_name, limit: 100 - t.string :email, limit: 100, null: false - - t.timestamps - end - add_idx = %Q(CREATE INDEX subscribe_users_email_idx ON subscribe_users using btree(email)) - execute add_idx - end -end diff --git a/db/schema.rb b/db/schema.rb index fa592a0..26c0742 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180404232602) do +ActiveRecord::Schema.define(version: 20180404232601) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -25,13 +25,4 @@ t.datetime "updated_at", null: false end - create_table "subscribe_users", force: :cascade do |t| - t.string "first_name", limit: 100 - t.string "last_name", limit: 100 - t.string "email", limit: 100, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "subscribe_users_email_idx" - end - end diff --git a/test/mailers/contact_mailer_test.rb b/test/mailers/contact_mailer_test.rb new file mode 100644 index 0000000..af056da --- /dev/null +++ b/test/mailers/contact_mailer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ContactMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/mailers/previews/contact_mailer_preview.rb b/test/mailers/previews/contact_mailer_preview.rb new file mode 100644 index 0000000..cd6ac4a --- /dev/null +++ b/test/mailers/previews/contact_mailer_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/contact_mailer +class ContactMailerPreview < ActionMailer::Preview + +end From 80ebe1182ea293a479ae54206a9ddafd1a70c5a0 Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Tue, 30 Oct 2018 23:08:59 +0530 Subject: [PATCH 2/9] Add application yml file --- config/application.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 config/application.yml diff --git a/config/application.yml b/config/application.yml new file mode 100644 index 0000000..cf84e68 --- /dev/null +++ b/config/application.yml @@ -0,0 +1,13 @@ +## Default Variables +FROM_EMAIL: 'sales@bushidolab.com' +HOST: '' + +## For Trigger Emails +TO_EMAILS: ['sales@bushidolab.com', 'sales@bushidolab.com', 'sales@bushidolab.com'] + +## SMTP Credentials +SMTP_ADDRESS: '' +SMTP_PORT: '' +SMTP_DOMAIN: '' +SMTP_USER_NAME: '' +SMTP_PASSWORD: '' From c91668e03a86fd7bdfaaf347ec2c4fb4f6f6a9c7 Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Wed, 31 Oct 2018 22:35:05 +0530 Subject: [PATCH 3/9] Remove application yml file --- config/application.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 config/application.yml diff --git a/config/application.yml b/config/application.yml deleted file mode 100644 index cf84e68..0000000 --- a/config/application.yml +++ /dev/null @@ -1,13 +0,0 @@ -## Default Variables -FROM_EMAIL: 'sales@bushidolab.com' -HOST: '' - -## For Trigger Emails -TO_EMAILS: ['sales@bushidolab.com', 'sales@bushidolab.com', 'sales@bushidolab.com'] - -## SMTP Credentials -SMTP_ADDRESS: '' -SMTP_PORT: '' -SMTP_DOMAIN: '' -SMTP_USER_NAME: '' -SMTP_PASSWORD: '' From 9b78af35b5a42937cffc72288cce855423a446e0 Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Thu, 1 Nov 2018 13:52:54 +0530 Subject: [PATCH 4/9] Change env variable name --- app/controllers/contacts_controller.rb | 2 +- app/mailers/contact_mailer.rb | 2 +- config/environments/development.rb | 2 +- config/environments/production.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index 8266e00..9f57420 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -1,6 +1,6 @@ class ContactsController < ApplicationController def create - ContactMailer.contact_send(contact_params).deliver + ContactMailer.contact_send(contact_params).deliver_now end private diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 9f81428..dbc83d7 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -2,6 +2,6 @@ class ContactMailer < ApplicationMailer def contact_send(contact) @contact = contact - mail(to: ENV['TO_EMAILS'], subject: 'Contact') + mail(to: ENV['TO_EMAILS'], subject: 'Contact', from: @contact['email']) end end diff --git a/config/environments/development.rb b/config/environments/development.rb index f8e25cd..ad8a3bc 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -53,7 +53,7 @@ config.file_watcher = ActiveSupport::EventedFileUpdateChecker ## SMTP Credentials - config.action_mailer.default_url_options = { host: ENV['HOST'] } + config.action_mailer.default_url_options = { host: ENV['SMTP_HOST'] } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { diff --git a/config/environments/production.rb b/config/environments/production.rb index 882e866..95cbf41 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -88,7 +88,7 @@ ## SMTP Credentials config.action_mailer.perform_deliveries = true - config.action_mailer.default_url_options = { host: ENV['HOST'] } + config.action_mailer.default_url_options = { host: ENV['SMTP_HOST'] } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { From 9d068a6d11548bc2e4f223bbb03f3e3f2316410c Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Sun, 11 Nov 2018 13:06:08 +0530 Subject: [PATCH 5/9] Add user send email and email content change --- app/controllers/contacts_controller.rb | 1 + app/mailers/contact_mailer.rb | 4 ++++ app/views/contact_mailer/contact_send.html.erb | 12 +----------- app/views/contact_mailer/user_send.html.erb | 10 ++++++++++ 4 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 app/views/contact_mailer/user_send.html.erb diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index 9f57420..ff73e72 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -1,6 +1,7 @@ class ContactsController < ApplicationController def create ContactMailer.contact_send(contact_params).deliver_now + ContactMailer.user_send(contact_params).deliver_now end private diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index dbc83d7..3527d92 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -4,4 +4,8 @@ def contact_send(contact) @contact = contact mail(to: ENV['TO_EMAILS'], subject: 'Contact', from: @contact['email']) end + + def user_send(contact) + mail(to: contact['email'], subject: 'Contact') + end end diff --git a/app/views/contact_mailer/contact_send.html.erb b/app/views/contact_mailer/contact_send.html.erb index 5091220..0d173da 100644 --- a/app/views/contact_mailer/contact_send.html.erb +++ b/app/views/contact_mailer/contact_send.html.erb @@ -4,16 +4,6 @@ -

Welcome to Bushido Lab

-

- <%= @contact[:first_name] %> -

-

- <%= @contact[:last_name] %> -

-

- <%= @contact[:email] %> -

-

Thanks for joining and have a great day!

+

<%= "#{@contact[:email]} has filled out request form." %>

diff --git a/app/views/contact_mailer/user_send.html.erb b/app/views/contact_mailer/user_send.html.erb new file mode 100644 index 0000000..efa6ed2 --- /dev/null +++ b/app/views/contact_mailer/user_send.html.erb @@ -0,0 +1,10 @@ + + + + + + +

Welcome to Bushido Lab

+

Thank You!

+ + From 315eb78898359cb47acd4d4b879e2c90925535a1 Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Sun, 11 Nov 2018 13:23:42 +0530 Subject: [PATCH 6/9] Change config for email trigger --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 95cbf41..e46cf3d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -64,7 +64,7 @@ # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. - config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = true # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). From ae4fa6bfced8b77a848431188f5af8cb24e81a70 Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Sun, 11 Nov 2018 13:31:05 +0530 Subject: [PATCH 7/9] Config changes --- config/environments/development.rb | 2 -- config/environments/production.rb | 2 -- 2 files changed, 4 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index ad8a3bc..d825277 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -63,8 +63,6 @@ user_name: ENV['SMTP_USER_NAME'], password: ENV['SMTP_PASSWORD'], authentication: :plain, - ssl: true, - tls: true, enable_starttls_auto: true } end diff --git a/config/environments/production.rb b/config/environments/production.rb index e46cf3d..8889770 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -98,8 +98,6 @@ user_name: ENV['SMTP_USER_NAME'], password: ENV['SMTP_PASSWORD'], authentication: :plain, - ssl: true, - tls: true, enable_starttls_auto: true } From 37c5604bef7e865ece1e3333cb85f0714ef5c709 Mon Sep 17 00:00:00 2001 From: Viral Mistry Date: Sun, 11 Nov 2018 15:24:02 +0530 Subject: [PATCH 8/9] Change single page to individual pages --- app/assets/javascripts/application.js | 17 +- app/assets/javascripts/site.js | 52 +++-- app/controllers/contacts_controller.rb | 3 + app/controllers/home_controller.rb | 14 ++ app/controllers/sites_controller.rb | 10 - app/views/application/_footer.html.erb | 52 +---- app/views/application/_nav_list.html.erb | 22 +- app/views/application/_navbar.html.erb | 6 +- app/views/contacts/index.html.erb | 44 ++++ app/views/home/about_us.html.erb | 38 ++++ app/views/home/index.html.erb | 43 ++++ app/views/home/our_team.html.erb | 265 +++++++++++++++++++++++ app/views/home/what_we_do.html.erb | 108 +++++++++ config/routes.rb | 7 +- 14 files changed, 576 insertions(+), 105 deletions(-) create mode 100644 app/controllers/home_controller.rb delete mode 100644 app/controllers/sites_controller.rb create mode 100644 app/views/contacts/index.html.erb create mode 100644 app/views/home/about_us.html.erb create mode 100644 app/views/home/index.html.erb create mode 100644 app/views/home/our_team.html.erb create mode 100644 app/views/home/what_we_do.html.erb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9166753..0cb7950 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,14 +16,14 @@ //= require_tree . $(function() { - $(window).scroll(function () { - if ($(this).scrollTop() > 820) { - $('.crazy-navbar').addClass('changeColor') - } - if ($(this).scrollTop() < 820) { - $('.crazy-navbar').removeClass('changeColor') - } - }); + // $(window).scroll(function () { + // if ($(this).scrollTop() > 820) { + // $('.crazy-navbar').addClass('changeColor') + // } + // if ($(this).scrollTop() < 820) { + // $('.crazy-navbar').removeClass('changeColor') + // } + // }); $('a').click(function(){ debugger @@ -31,4 +31,3 @@ $(function() { $('body').addClass('fadeIn') }) }); - diff --git a/app/assets/javascripts/site.js b/app/assets/javascripts/site.js index e285353..0e6f275 100644 --- a/app/assets/javascripts/site.js +++ b/app/assets/javascripts/site.js @@ -3,25 +3,39 @@ $(function(){ e.preventDefault(); var self = $(this); - $.ajax({ - method: "POST", - url: self.data('url'), - dataType: 'JSON', - data: { - contact: { - first_name: $("#first_name").val(), - last_name: $("#last_name").val(), - email: $("#email").val(), - } + if ($("#first_name").val() != "" && $("#last_name").val() != "" && $("#email").val() != "") { + if (isEmail($("#email").val())) { + $('.return-msg').html(''); + $.ajax({ + method: "POST", + url: self.data('url'), + dataType: 'JSON', + data: { + contact: { + first_name: $("#first_name").val(), + last_name: $("#last_name").val(), + email: $("#email").val(), + } + } + }).done(function(data){ + $("#first_name").val("") + $("#last_name").val("") + $("#email").val("") + $("#first_name").focus() + }).fail(function(error){ + var data = error; + console.log("==data", data) + }) + } else { + $('.return-msg').html('Email is invalid.'); } - }).done(function(data){ - $("#first_name").val("") - $("#last_name").val("") - $("#email").val("") - $("#first_name").focus() - }).fail(function(error){ - var data = error; - console.log("==data", data) - }) + } else { + $('.return-msg').html('Please fill all the fields.'); + } }) }) + +function isEmail(email) { + var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; + return regex.test(email); +} diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index ff73e72..a08f3ac 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -1,4 +1,7 @@ class ContactsController < ApplicationController + def index + end + def create ContactMailer.contact_send(contact_params).deliver_now ContactMailer.user_send(contact_params).deliver_now diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..ba2c900 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,14 @@ +class HomeController < ApplicationController + + def index + end + + def about_us + end + + def what_we_do + end + + def our_team + end +end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb deleted file mode 100644 index c917cc4..0000000 --- a/app/controllers/sites_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -class SitesController < ApplicationController - - def show - @site = Site.find_by_slug(params[:slug] || 'home') - - respond_to do |format| - format.html - end - end -end diff --git a/app/views/application/_footer.html.erb b/app/views/application/_footer.html.erb index 297dfb7..86b6fe6 100644 --- a/app/views/application/_footer.html.erb +++ b/app/views/application/_footer.html.erb @@ -2,57 +2,7 @@ -