Method: ApiClient::Errors#unique_message

Defined in:
lib/api-client/errors.rb

#unique_message(attribute) ⇒ String

Returns a unique message for a given attribute.

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.unique_message(:name) # => "is too short (minimum is 5 characters) and can't be blank"
person.errors.unique_message(:address) # => nil

Parameters:

  • attribute (String)

    The attribute to check for joined error messages.

Returns:

  • (String)

    A string with all errors from the given attribute joined.



44
45
46
47
# File 'lib/api-client/errors.rb', line 44

def unique_message(attribute)
  return '' if messages[attribute].blank?
  [messages[attribute]].flatten.to_sentence
end