2011-03-08 1 views
2

이 코드를 감안할 때 :CouchRest이 검증되지 않은 데이터 유형

class House < CouchRest::Model::Base 
    use_database DB 
    property :somedumfield, :type => Integer 
end 
나는 숫자 또는 텍스트 데이터를 입력 할 수 있습니다

; 그것을 데이터베이스에 저장하고 오류는 발생하지 않습니다. 나는 couchrest를 사용하는 소파 모델을 사용하고 있는데, 어떻게 필드에 데이터 유형에 대한 유효성 검사를 추가 할 수 있습니까?

미리 감사드립니다.

답변

0

CouchRest와는 아무 관계도 없습니다. 소파 모델 기능입니다.

소파 모델 소스를 보면 #to_i 메소드를 사용하여 제공된 값을 전송 한 것처럼 보입니다. 그래서 "foo".to_i => 0.

couch_model doc 그 내용은 CouchRest Model automatically includes the new ActiveModel validations, so they should work just as the traditional Rails validations. For more details, please see the ActiveModel::Validations documentation.이므로 사용해 보시길 바랍니다!