在 ruby on Rails 中 有没有办法规定通过 Activerecord 插入数据库的字段的格式?
我通过 ActiveRecord 将一些字符串(看起来像日期)插入到 sqlite3 数据库中,并且数据库正在更改字段并使其看起来像日期。例如:
"4-2" => "2-Apr" #Not only a date but the order has been reversed.
"6-7-12" => "7/12/2006" #Again not only a date but the order has been changed.
我寻找一个可以防止这种情况发生的 ruby 字符串函数,但没有找到任何结果。
有其他人遇到过类似的情况吗?您是否知道任何解决方法或修复方法。
I'm inserting some strings (that look dates) into a sqlite3 database via my ActiveRecord and the database is altering the field and making it look like a date. For example:
"4-2" => "2-Apr" #Not only a date but the order has been reversed.
"6-7-12" => "7/12/2006" #Again not only a date but the order has been changed.
I looked for a ruby string function that would prevent this from happening but haven't been able to come up with anything.
Has anyone else come across something like this and are you aware of any workarounds or fixes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以预测字符串的格式,请在保存之前使用以下代码将字符串解析为日期对象。
If you can predict the format of the string, use the following code to parse the string into date object before saving it.