parent
7f433cf223
commit
f8c91add3e
@ -1,5 +1,20 @@
|
|||||||
class HomeController < ApplicationController
|
class HomeController < ApplicationController
|
||||||
|
skip_before_action :verify_authenticity_token
|
||||||
def index
|
def index
|
||||||
@contact = Contact.new
|
@contact = Contact.new
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
class Contact < MailForm::Base
|
class Contact < MailForm::Base
|
||||||
attribute :name, validate: true
|
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 :organization
|
||||||
attribute :message
|
attribute :message, validate: true
|
||||||
attribute :nickname, captcha: true
|
attribute :nickname, captcha: true
|
||||||
|
|
||||||
# Declare the e-mail headers. It accepts anything the mail method
|
# Declare the e-mail headers. It accepts anything the mail method
|
||||||
# in ActionMailer accepts.
|
# in ActionMailer accepts.
|
||||||
def headers
|
def headers
|
||||||
{
|
{
|
||||||
:subject => "Contact Form Inquiry",
|
subject: 'Contact Form Inquiry',
|
||||||
:to => ENV['CONTACT_FORM_DESTINATION'] || "memoryman51@hotmail.com",
|
to: ENV['CONTACT_FORM_DESTINATION'] || 'memoryman51@hotmail.com',
|
||||||
:from => %("#{name}" <#{email}>)
|
from: %("#{name}" <#{email}>)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<div class="container pb-5">
|
<div class="container pb-5">
|
||||||
<h1>Contact Form</h1>
|
<h1>Contact Form</h1>
|
||||||
<%= form_for @contact do |f| %>
|
<%= form_for @contact, url: home_index_path, method: :create, data: { turbo: false } do |f| %>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<%= f.label :name %></br>
|
<%= f.label :name %></br>
|
||||||
<%= f.text_field :name, required: true, class: "contact-form-text-area" %></br>
|
<%= f.text_field :name, required: true, class: "contact-form-text-area" %></br>
|
||||||
@ -1 +1 @@
|
|||||||
<%= render(partial: "new") %>
|
<%= render(partial: "contacts/contact_form") %>
|
||||||
|
|||||||
Loading…
Reference in new issue