Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To add a Thank You page that remains static when a form is submitted using Rails, you can follow these steps:

  1. Create a new view file for the Thank You page, such as thank_you.html.erb, in the views directory of your Rails application.

  2. In the controller action that processes the form submission, redirect the user to the Thank You page instead of rendering a view. For example, if your form is submitted to the create action of a ContactsController, you could add the following code to the end of the action:

redirect_to thank_you_path

This assumes that you have defined a route for the Thank You page using the get method in your config/routes.rb file:

get 'thank_you', to: 'contacts#thank_you', as: 'thank_you'
  1. In the thank_you.html.erb view, you can display a static message of your choice to thank the user for submitting the form. For example:
<h1>Thank you for submitting the form!</h1>
<p>Your message has been sent and we will get back to you as soon as possible.</p>
  1. Finally, you may want to customize the layout of the Thank You page by creating a new layout file or specifying a different layout in the controller. This would allow you to add a header, footer, or other elements to the page that are consistent with the rest of your application.