2

Given this code :

class House < CouchRest::Model::Base
  use_database DB
  property :somedumfield, :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

Salvador Aceves
  • 348
  • 1
  • 4
  • 13

1 Answers1

0

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!

sinm
  • 1,357
  • 12
  • 16