Fix NoMethodError in admin user form validation - handle nil class attribute #3701
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When creating users through the admin interface (
/admin/users) with invalid form data, the application was returning a 500 Internal Server Error instead of displaying helpful validation error messages. This occurred due to aNoMethodErrorin the form error handling code.The specific error was:
This happened when form fields didn't have an existing
classattribute, causingelement["class"]to returnnil, and the code attempted to concatenate a string tonilusing the+operator.Solution
Fixed the
field_error_procinconfig/initializers/action_view_fields_with_errors.rbto safely handle nil class attributes:Before (buggy code):
After (fixed code):
Testing
Added comprehensive tests to ensure the fix works correctly:
Unit tests for the field error proc covering:
Integration tests for admin user creation scenarios:
Impact
is-invalidCSS class on validation errorsThis fix resolves the core issue where validation failures in the admin interface caused server crashes instead of displaying user-friendly error messages.
Fixes #3700.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.