include?

include?(attribute) Instance Public methods Returns true if the error messages include an error for the given key attribute, false otherwise. person.errors.messages # => {:name=>["cannot be nil"]} person.errors.include?(:name) # => true person.errors.include?(:age) # => false has_key?

has_key?

has_key?(attribute) Instance Public methods aliases include? include?

get

get(key) Instance Public methods Get messages for key. person.errors.messages # => {:name=>["cannot be nil"]} person.errors.get(:name) # => ["cannot be nil"] person.errors.get(:age) # => nil

generate_message

generate_message(attribute, type = :invalid, options = {}) Instance Public methods Translates an error message in its default scope (activemodel.errors.messages). Error messages are first looked up in models.MODEL.attributes.ATTRIBUTE.MESSAGE, if it's not there, it's looked up in models.MODEL.MESSAGE and if that is not there also, it returns the translation of the default message (e.g. activemodel.errors.messages.MESSAGE). The translated model name, translated attribute name and th

full_messages_for

full_messages_for(attribute) Instance Public methods Returns all the full 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.full_messages_for(:name) # => ["Name is too short (minimum is 5 characters)", "Name can't be blank"]

full_messages

full_messages() Instance Public methods Returns all the full error messages in an array. class Person validates_presence_of :name, :address, :email validates_length_of :name, in: 5..30 end person = Person.create(address: '123 First St.') person.errors.full_messages # => ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Email can't be blank"]

full_message

full_message(attribute, message) Instance Public methods Returns a full message for a given attribute. person.errors.full_message(:name, 'is invalid') # => "Name is invalid"

empty?

empty?() Instance Public methods Returns true if no errors are found, false otherwise. If the error message is a string it can be empty. person.errors.full_messages # => ["name cannot be nil"] person.errors.empty? # => false blank?

each

each() Instance Public methods Iterates through each error key, value pair in the error messages hash. Yields the attribute and the error for that attribute. If the attribute has more than one error message, yields once for each error message. person.errors.add(:name, "can't be blank") person.errors.each do |attribute, error| # Will yield :name and "can't be blank" end person.errors.add(:name, "must be specified") person.errors.each do |attribute, error| # Will yield :name and

delete

delete(key) Instance Public methods Delete messages for key. Returns the deleted messages. person.errors.get(:name) # => ["cannot be nil"] person.errors.delete(:name) # => ["cannot be nil"] person.errors.get(:name) # => nil