开发者

CouchRest is not validating data types

Given this code :

class House < CouchRest::Model::Base
  use_database DB
  property :s开发者_StackOverflow中文版omedumfield, :type => Integer
end

I can enter either Numeric or Text data; it saves it to the database and no errors are raised; I am using couch-model (which uses couchrest), how can I add a validation for data types on fields.

Thanks in advance


Nothing to do with CouchRest. It's a couch-model feature.

Looking in couch-model source it seems they cast provided value using #to_i method. So "foo".to_i => 0.

couch_model doc states that 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. So you're welcome to try that out!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜