我试图修改模型的after_validation回调模型中的属性,但所有@attributes都返回nil,因此该方法失败。after_validation块中的模型访问属性
如何在保存之前,但在验证之后访问ActiveRecord的@attributes。 我正试图从类中的方法访问它。
class Business < ActiveRecord::Base
attr_accessible :latitude, :longitude
geocoded_by :address
after_validation :geocode
# Returns a human readable address from our various fields
def address
# All of these are nil when this gets called, from the geocode block which gets called by after_validation
[self.street + self.street2, self.city, self.state].compact.join(', ')
end
end
后一些代码。 – 2012-01-08 20:59:34
没有太多的帖子,但肯定:) – 1dayitwillmake 2012-01-08 21:32:32