Mongomapper:最低和最低:最大值:长度

时间:2013-04-20 12:25:41

标签: ruby activerecord mongomapper

我尝试在MongoMapper中验证一个字符串:

key :title,       String, :require => true, :length => 4..30

当字符串超过4个字符时,我总是得到错误“标题太短(最少4个字符)”。

如果我尝试

key :title,       String, :require => true, :minimum => 4, :maximum => 30

它作为例外工作。有人可以解释为什么会发生这种情况或为什么第一件事是错的?

1 个答案:

答案 0 :(得分:0)

MongoMapper使用Activerecord验证。从他们的文档:validates :password, :length => { :in => 6..20 }所以你必须使用:in来表示你正在使用范围。见http://guides.rubyonrails.org/active_record_validations_callbacks.html#length

相关问题