2012-06-16 7 views
2

나는 나의 레일 앱에서 validates_confirmation_of을 깨뜨린 것 같다.나는 깨진 것 같다 validates_confirmation_of

내 모델은 다음과 같습니다

0 HAL work/nrb-brewery-management % rails c 
Loading development environment (Rails 3.2.5) 

1.9.3p0 :001 > b = Blark.new 
=> #<Blark:0xae2e2d0> 

1.9.3p0 :002 > b.text = 'llama' 
=> "llama" 

1.9.3p0 :003 > b.text_confirmation 
=> nil 

1.9.3p0 :004 > b.valid? 
=> true 

왜 여기 유효 b입니다 :

class Blark 
    include ActiveModel::Validations 
    attr_accessor :text 
    validates_confirmation_of :text 
end 

이 내가 그것을 사용할 때 무슨 일입니까?

답변

4

Rails documentation 상태 :

"참고 :이 검사는 password_confirmation이 전무하지 않고, 기본적으로 단지에 저장할 경우에만 수행됩니다 확인 속성의 존재 검사를 추가해야합니다, 확인을 요구하려면."

클래스에 존재 확인을 추가하십시오. 예 :

class Blark 
    include ActiveModel::Validations 
    attr_accessor :text 
    validates_confirmation_of :text 
    validates_presence_of :text, :text_confirmation 
end 
관련 문제