我有一些身份证214001, 214002, 215001, etc...
我想要从搜索栏中自动完成 ID
“214”应该触发 ID 自动完成214001
, 214002
显然,我不能只是做一个
scope :by_number, ->(number){
where(:number => /#{number.to_i}/i)
}
与蒙古人。有人知道将 mongoid Integer 字段与正则表达式匹配的工作方法吗?
This question https://stackoverflow.com/questions/2908100/mongodb-regex-search-on-integer-value有一些线索,但我怎样才能在 Rails 中做到这一点?
EDIT:上下文是能够通过其整数 ID 或其简短描述找到项目:
scope :by_intitule, ->(regex){
where(:intitule => /#{Regexp.escape(regex)}/i)
}
# TODO : Not working !!!!
scope :by_number, ->(numero){
where(:number => /#{number.to_i}/i)
}
scope :by_name, ->(regex){
any_of([by_number(regex).selector, by_intitule(regex).selector])
}