instance method
messages_for
Ruby on Rails 7.1.6
Since v6.1.7.10Signature
messages_for(attribute)
Returns all the error messages for a given attribute in an array.
class Person validates_presence_of :name, :email validates_length_of :name, in: 5..30 end person = Person.create() person.errors.messages_for(:name) # => ["is too short (minimum is 5 characters)", "can't be blank"]
Parameters
-
attributereq
Source
# File activemodel/lib/active_model/errors.rb, line 444
def messages_for(attribute)
where(attribute).map(&:message)
end
Defined in activemodel/lib/active_model/errors.rb line 444
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Errors