2010-12-29 8 views
1

유효성 검사 방법 내에서 유효성 검사를 실행할 때 다음 코드가 실행됩니다. 검증이 실패로레일 유효성 검사 및 롤백

def validate 
    if self.limit_reached = true 
     self.errors.add('plan', 'limit reached') 
     self.account_setting.update_attribute(:email_sent, true) 
    end 
end 

그러나이 업데이트가 롤백되고, 어떻게

+0

왜 롤백을 방지 하시겠습니까? 어떤 의미가 없습니까? – Lichtamberg

+0

if self.limit_reached = true 일 것입니다. self.limit_reached == true (double equal) - 문제가 해결되었지만 확실하게 문제를 해결할 수 있는지 확신하지 못합니다. – house9

답변

3

이 시도 롤백되는이 하나의 업데이트를 방지 할 수 있습니다 :

def validate 
    if self.limit_reached 
    self.errors.add('plan', 'limit reached') 
    @set_email_sent = true 
    return false 
    end 
end 

def after_rollback 
    if @set_email_sent 
    self.account_setting.update_attribute(:email_sent, true) 
    end 
end 

는 희망이 도움이!

관련 문제