rails form validation custom message

To create a custom validation message in a Ruby on Rails form, you can follow these steps:

  1. Open the model file where you want to add the validation. This is typically located in the app/models directory and has a .rb extension.

  2. Inside the model class, use the validates method to define the validation rule. For example, let's say we want to validate the presence of a name attribute and provide a custom error message if it is blank. The code would look like this:

validates :name, presence: { message: 'Custom error message' }
  1. Save the model file.

By following these steps, you have added a custom validation message for the name attribute in your Ruby on Rails form.