1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

r1618@asus: jeremy | 2005-07-03 08:24:19 -0700

base attribute_present? on blank?, accounting for zero


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1636 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2005-07-03 08:33:03 +00:00
parent 67adc0b5b3
commit b210edce38

View file

@ -1079,8 +1079,8 @@ module ActiveRecord #:nodoc:
# Returns true if the specified +attribute+ has been set by the user or by a database load and is neither # Returns true if the specified +attribute+ has been set by the user or by a database load and is neither
# nil nor empty? (the latter only applies to objects that responds to empty?, most notably Strings). # nil nor empty? (the latter only applies to objects that responds to empty?, most notably Strings).
def attribute_present?(attribute) def attribute_present?(attribute)
is_empty = read_attribute(attribute).respond_to?("empty?") ? read_attribute(attribute).empty? : false value = read_attribute(attribute)
@attributes.include?(attribute) && !@attributes[attribute].nil? && !is_empty !value.blank? or value == 0
end end
# Returns an array of names for the attributes available on this object sorted alphabetically. # Returns an array of names for the attributes available on this object sorted alphabetically.