我試圖修改模型的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