diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index ff3df1a..92b789d 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,5 +1,20 @@ class HomeController < ApplicationController + skip_before_action :verify_authenticity_token def index @contact = Contact.new end + + def create + puts '***************************** Inside home controller *****************************************' + + flash.now[:success] = 'Message sent!' + @contact = Contact.new(params[:contact]) + @contact.request = request + if @contact.deliver + flash.now[:success] = 'Message sent!' + else + flash.now[:error] = 'Could not send message' + end + render :index + end end diff --git a/app/models/contact.rb b/app/models/contact.rb index c507a33..fc46a4f 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -1,17 +1,17 @@ class Contact < MailForm::Base attribute :name, validate: true - attribute :email, validate: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i + attribute :email, validate: /\A([\w.%+\-]+)@([\w\-]+\.)+(\w{2,})\z/i attribute :organization - attribute :message - attribute :nickname, captcha: true + attribute :message, validate: true + 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}>) + 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/_contact_form.html.erb similarity index 90% rename from app/views/contacts/_new.html.erb rename to app/views/contacts/_contact_form.html.erb index 4dc9b6e..e52a3ea 100644 --- a/app/views/contacts/_new.html.erb +++ b/app/views/contacts/_contact_form.html.erb @@ -1,6 +1,6 @@