Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有一种简单的内置方法来检查字符串是否是有效的 ObjectId?我知道如果我尝试从无效字符串构造 ObjectId 会引发异常,有没有办法绕过 try-catch 块?
一种可能的方法是检查这个正则表达式:^[0-9a-b]{48}$ 有没有更优雅的东西?
^[0-9a-b]{48}$
有方法ObjectId.isValid(String s):文档
ObjectId.isValid(String s)
我的 rails 应用程序正在生成以下错误(运行 rails 生成器或启动 WEBrick 时):
/home/lachlan/.gem/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/dynamic_matchers.rb:50:in `method_