Read more

Always show all form errors during development

Henning Koch
August 26, 2011Software engineer at makandra GmbH

You've been there: A form cannot be submitted, but you don't see a validation error because the field at fault has no corresponding input field on the form. Because this is usually a bug, you insert debug information listing all errors into the form view. And once the bug is fixed, you forget to take out that debug information.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

There is a better way. By copying one of the attached initializers into config/initializers, your forms will always render a small box listing all form errors in the bottom right corner of the screen. This box is never shown in environments other than development.

For older Ruby versions, use form_for_with_development_errors.rb. This monkey patches only form_for. For newer Ruby versions, use form_with_development_errors.rb. This monkey patches both form_for and form_with.

Rails-XSS is required by default. So if your project doesn't support Rails-XSS just remove all .html_safe calls.

Example

Posted by Henning Koch to makandra dev (2011-08-26 12:13)