method

messages_for

Importance_1
v7.1.3.4 - Show latest stable - 0 notes - Class: ActiveModel::Errors
messages_for(attribute) public

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"]
Show source
Register or log in to add new notes.