모델의 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
후 일부 코드. –
그다지 그다지 게시하지는 않지만 확실하다. :) – 1dayitwillmake