Contact forms

The contact form component adds a Contact page (view), which displays a contact form, along with a controller to process form submissions and a mailer to send form submissions to an email address.

It also includes a spam protection widget powered by Cloudflare Turnstile. The Cloudflare Turnstile implementation uses the railscloudflareturnstile gem.

Installation

You can install the contact form component by running the following command:

Copy
rails g instrumental:contact_form

Follow the instructions in the Cloudflare Turnstile documentation to configure Cloudflare Turnstile.

View your Contact Form

Be sure to restart your server after saving your Rails credentials and initalizer.

Now your Contact form should be viewable at /contact.

Note: Your contact_controller.rb has allow_unauthenticated_access which makes your Contact view and form submissions available to the public. If you want it to be available only to logged-in users, then remove allow_unauthenticated_access (assuming you’re using Rails authentication, which is what Instrumental Authentication Component is built on).

Contact Form Mailer

The Contact Form component installs contact_mailer.rb along with an HTML and text email. This sends the contact form submissions to an email address of your choosing.

The email address that submissions are sent to is defined in contact_mailer.rb

Submission emails are set up to include the following:

  • The submitter’s subject line, preceded by [AppName Contact]
  • Reply-to set to the submitter’s email address
  • The submitter’s name and email address
  • Body content containing the submitter’s message
  • Body content also displays the page URL where the Contact form was submitted from
Instrumental Components

I created Instrumental Components to make designing and building professional apps with Ruby on Rails easy, fast, and fun. I use it on all of my projects and I hope it helps you build something great.

Brian Casel
Brian Casel
Creator of Instrumental Components
Learn more Send me a question or request