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.
我的 Postgres 数据库中有 jsonb 列,并且我有一个带有 pref["date"] date_field 的表单供用户使用。
如果转换为日期会下降,我如何转换为日期并验证 user.pref["date"] 是没有错误的日期?
您可以挽救无效日期转换的异常,然后添加错误
begin date = Date.parse(pref['date']) rescue ArgumentError # add error for invalid date end