Skip to content

Loading…

change param name to improve documentation #6829

Merged
merged 1 commit into from

3 participants

@frodsan

The keys of the error messages are actually attribute names. It makes
the documentation easier to understand:

# Returns +true+ if the error messages include an error for the given
# +attribute+, +false+ otherwise.
#
#   person.errors.messages # => { :name => ["can not be nil"] }
#   person.errors.include?(:name) # => true
#   person.errors.include?(:age)  # => false
def include?(attribute)
  (v = messages[attribute]) && v.any?
end
Francesco Rodriguez change param name to improve documentation
The keys of the error messages are actually attribute names. It makes
the documentation easier to understand:

    # Returns +true+ if the error messages include an error for the given
    # +attribute+, +false+ otherwise.
    #
    #   person.errors.messages # => { :name => ["can not be nil"] }
    #   person.errors.include?(:name) # => true
    #   person.errors.include?(:age)  # => false
    def include?(attribute)
      (v = messages[attribute]) && v.any?
    end
629bc03
@rafaelfranca rafaelfranca merged commit a232831 into rails:master
@frodsan

More examples in the same module:

  • def add(attribute, message = nil, options = {})
  • def [](attribute)
  • def []=(attribute, error)
  • ...
@splattael

In the docs +error+ should read +attribute+

Uh oh, I didn't see that commit. Sorry for the noise :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 22, 2012
  1. change param name to improve documentation

    Francesco Rodriguez committed
    The keys of the error messages are actually attribute names. It makes
    the documentation easier to understand:
    
        # Returns +true+ if the error messages include an error for the given
        # +attribute+, +false+ otherwise.
        #
        #   person.errors.messages # => { :name => ["can not be nil"] }
        #   person.errors.include?(:name) # => true
        #   person.errors.include?(:age)  # => false
        def include?(attribute)
          (v = messages[attribute]) && v.any?
        end
Showing with 2 additions and 2 deletions.
  1. +2 −2 activemodel/lib/active_model/errors.rb
View
4 activemodel/lib/active_model/errors.rb
@@ -87,8 +87,8 @@ def clear
end
# Do the error messages include an error with key +error+?
- def include?(error)
- (v = messages[error]) && v.any?
+ def include?(attribute)
+ (v = messages[attribute]) && v.any?
end
alias :has_key? :include?
Something went wrong with that request. Please try again.