I’m running into an interesting problem where an ActiveRecord instance
#valid? returns false, but #errors#full_messages is empty.
This is in one of my models. The code was run in ruby-debug sitting in
one of my validation methods.
(rdb:1) self.publisher_address.valid?
false
(rdb:1) self.publisher_address.errors.full_messages
[]
(rdb:1) a = Address.new(self.publisher_address.attributes)
(rdb:1) a.valid?
false
(rdb:1) a.errors.full_messages
[“User can’t be blank”, “City can’t be blank”…]
self.publisher_address is an unsaved Address object, created using
Address.new. So is a, which I just created. Both are invalid, yet a
has error messages like it should but self.publisher_address doesn’t.
I can’t figure out why.
(rdb:1) self.publisher_address
#<Address id: nil, user_id: nil,…>
(rdb:1) a
#<Address id: nil, user_id: nil,…>
(rdb:1) self.publisher_address.class
Address(id: integer, user_id: integer,…)
(rdb:1) a.class
Address(id: integer, user_id: integer,…)
The #publisher_address method in this model is custom, not an
association. I get the hash of the attributes and do
return Address.new(publisher_address_attributes)
self.publisher_address.errors is an AR::Errors object, but the actual
errors are blank:
(rdb:1) self.publisher_address.errors
#<ActiveRecord::Errors:0x2cddf50 @base=#<Address id: nil, user_id:
nil,…>, @errors=#<OrderedHash {}>>
Has anyone seen empty errors like this before?