The process_contact_form
method is where you can react to the incoming form data, send it to a user as an email message, forward it to your CRM system, or do whatever your needs require. For simplicity's sake, we're just writing a log entry.
The form_params
method uses strong parameters to ensure that only the expected data is passed to the ContactForm.
The create
method should seem familiar to you. It first creates a ContactForm using the form_params
method, validates it and, depending on the outcome of the validation, either processes the form and renders a confirmation text, or rerenders the form with the errors included.
Please note, our calls to render
include the layout: false
flag. This instructs Rails not to render the application layout but just the template.
We also require a route for our controller to make it accessible: