To add a Thank You page that remains static when a form is submitted using Rails, you can follow these steps:
Create a new view file for the Thank You page, such as thank_you.html.erb
, in the views
directory of your Rails application.
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'
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>
Asked: 2023-05-08 00:10:28 +0000
Seen: 17 times
Last updated: May 08 '23