instance method add

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

add(attribute, message = nil, options = {})

Adds an error message (messsage) to the attribute, which will be returned on a call to on(attribute) for the same attribute and ensure that this error object returns false when asked if empty?. More than one error can be added to the same attribute in which case an array will be returned on a call to on(attribute). If no messsage is supplied, :invalid is assumed. If message is a Symbol, it will be translated, using the appropriate scope (see translate_error).

Parameters

attribute req
message opt = nil
options opt = {}
Source
# File activerecord/lib/active_record/validations.rb, line 46
    def add(attribute, message = nil, options = {})
      message ||= :invalid
      message = generate_message(attribute, message, options) if message.is_a?(Symbol)
      @errors[attribute.to_s] ||= []
      @errors[attribute.to_s] << message
    end

Defined in activerecord/lib/active_record/validations.rb line 46 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Errors

Type at least 2 characters to search.

↑↓ navigate · open · esc close