Repository navigation
Conversation
`ActiveModel::Error.full_message` and `.generate_message` call
`String#remove`, which is defined in
`active_support/core_ext/string/filters`, but error.rb doesn't require
it. Unless something else has loaded it (including
`ActiveModel::Validations` does), `full_messages` raises for an
attribute with a dot or a bracket in its name:
require "active_model"
# Person as in the ActiveModel::Errors docs, without Validations
person.errors.add(:"address.street", "can't be blank")
person.errors.full_messages
# NoMethodError: undefined method 'remove' for an instance of String
On 8.1 and earlier `full_message` calls `remove` for every attribute,
so the minimal implementation in the `ActiveModel::Errors` docs raises
on `full_messages` as written.
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation / Background
This Pull Request has been created because
ActiveModel::Error.full_messageandActiveModel::Error.generate_messagecallString#remove, which is defined inactive_support/core_ext/string/filters, butactive_model/error.rbdoesn't require it.Including
ActiveModel::Validationsloads it through another file, so it doesn't show up there or in the Active Model test suite. A model that only usesActiveModel::Errors, as in the minimal implementation in theActiveModel::Errorsdocs, raises fromfull_messageswhen an attribute name has a dot:With
extend ActiveModel::Translation,generate_messageraises the same way for an attribute with a bracket, likeerrors.add(:"tags[0]", :blank).On 8.1 (and 7.1)
full_messagecallsremovefor every attribute, so the example in theActiveModel::Errorsdocs raises as written. I reproduced that with the released gems:Detail
This Pull Request adds the missing require, the same fix #57310 made for
ActiveModel::SchematizedJson.Additional information
The snippets above print
["address.street can't be blank"]and["Tags[0] can't be blank"]with the change. I didn't add a test because something in the Active Model suite always loadsString#removefirst; I checked the snippets in separate processes instead.Tests run:
activemodel:bin/test(1271 runs, 0 failures).bundle exec rubocop activemodel/lib/active_model/error.rb: no offenses.No CHANGELOG entry as it is a minor fix, like #57310 and #59899. Happy to add one if preferred.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]