diff --git a/app/controllers/contact_controller.rb b/app/controllers/contact_controller.rb index 79f3e44da954f04b800c248c4264ea79abc9a9c4..a0463233e17d8bf17d868fd680fd23327717779a 100644 --- a/app/controllers/contact_controller.rb +++ b/app/controllers/contact_controller.rb @@ -4,7 +4,12 @@ class ContactController < ApplicationController end def sendmessage - - redirect_to homepage_path + if params[:email].blank? + flash[:alert] = 'Blank email' + redirect_to contact_path + else + ContactMailer.contact_email(params[:email], params[:message]).deliver_now + redirect_to homepage_path + end end end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d139960190594225e0134fe1a5c05370..ce92e2edbba2f5efdb46ef8456f2f7cf6ed4bc0e 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 to: 'admim@team.com', from: 'a@customer.com' layout 'mailer' end diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb new file mode 100644 index 0000000000000000000000000000000000000000..6de699adfcb61efac8465ac86ca31d10662b8542 --- /dev/null +++ b/app/mailers/contact_mailer.rb @@ -0,0 +1,9 @@ +class ContactMailer < ApplicationMailer + + def contact_email(email, message) + @email = email + @message = message + + mail cc: email + end +end diff --git a/app/views/contact/contact.html.haml b/app/views/contact/contact.html.haml index cfe69979479e82e0a2fc88035ef9a8741c2981a3..2faa1c9265899f1f5aac9e527f3cbe0d41817db8 100644 --- a/app/views/contact/contact.html.haml +++ b/app/views/contact/contact.html.haml @@ -1,5 +1,8 @@ %h1= "Contact Us" +- flash.each do |key, value| + = content_tag :div, content_tag(:p, value), id: "#{key}" unless value.blank? + = form_tag sendmessage_path, method: 'post' do = label_tag :name, "Email" diff --git a/app/views/contact_mailer/contact_email.html.haml b/app/views/contact_mailer/contact_email.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..2571803e32853a77e3bf10e781012e257b297a7c --- /dev/null +++ b/app/views/contact_mailer/contact_email.html.haml @@ -0,0 +1,4 @@ +%p= "Customer Email: " + @email +%br +%p= "Message:" +%p= @message \ No newline at end of file diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..cbf6b8e2e00d42371d74b48a9476f924b13bb406 --- /dev/null +++ b/app/views/layouts/mailer.html.haml @@ -0,0 +1,8 @@ +!!! +%html + %head + %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/ + :css + /* Email styles need to be inline */ + %body + = yield diff --git a/app/views/layouts/mailer.text.haml b/app/views/layouts/mailer.text.haml new file mode 100644 index 0000000000000000000000000000000000000000..0a90f092c5b3e76310ce4ed12814f0cb316b9200 --- /dev/null +++ b/app/views/layouts/mailer.text.haml @@ -0,0 +1 @@ += yield diff --git a/test/mailers/contact_mailer_test.rb b/test/mailers/contact_mailer_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..fabcff055e53b8ffb42dde5d5ac668f2591dfe87 --- /dev/null +++ b/test/mailers/contact_mailer_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class ContactMailerTest < ActionMailer::TestCase + test 'should return contact email' do + mail = ContactMailer.contact_email('kieran@dore.com', "what's up bro") + assert_equal ['admin@team.com'], mail.to + assert_equal ['no@one.com'], mail.from + 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 0000000000000000000000000000000000000000..ab080a0980901572301d0d8a55779a2072e70ec8 --- /dev/null +++ b/test/mailers/previews/contact_mailer_preview.rb @@ -0,0 +1,6 @@ +# Preview all emails at http://localhost:3000/rails/mailers/contact_mailer +class ContactMailerPreview < ActionMailer::Preview + def contact_email + ContactMailer.contact_email('some@one.com', 'watm') + end +end \ No newline at end of file