给定以下代码:
class House < CouchRest::Model::Base
use_database DB
property :somedumfield, :type => Integer
end我可以输入数字或文本数据;它会将数据保存到数据库中,并且不会引发错误;我使用的是couch-model (使用couchrest),如何在字段中添加数据类型的验证。
提前感谢
发布于 2012-03-17 22:18:26
和CouchRest无关。这是一个沙发模型的特征。
查看沙发模型源代码,他们似乎使用#to_i方法转换了提供的值。所以"foo".to_i => 0。
couch_model文档中提到了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.,所以欢迎你尝试一下!
https://stackoverflow.com/questions/5237417
复制相似问题