74. Controller Triggers the Mailer

  • We need to tell the Rails app when exactly to send the email upon form submission.
  • We do that in the controller file, but first we have to grab the form inputs using the params code below.

###app/controllers/contacts_controller.rb

...
name = params[:contact][:name]
email = params[:contact][:email]
body = params[:contact][:comments]
ContactMailer.contact_email(name, email, body).deliver
...

###Terminal

git status
git add .
git commit -m "Added contact form mailer view"
git push origin contact_form

Complete and Continue