假设我有一个Post Model。
数据库中的一条记录将是:
23|title_here|content_here|2011-02-20 08:01:55.583222|2011-02-20 08:01:55.583222
最后两个字段(2011-02-20 08:01:55.583222|2011-02-20 08:01:55.583222
)是created_at和updated_at字段。
然后,
post = Post.find_by_id(23)
Question:如何在数据库中获取created_at字符串:"2011-02-20 08:01:55.583222
“?
正如我们所知,post.created_at将返回一个ActiveSupport::TimeWithZone
对象,而不是原始字符串。
请帮助:)
发布于 2011-02-20 21:35:50
Post.find(23).attributes_before_type_cast["created_at"]
或
Post.find(23).read_attribute_before_type_cast("created_at")
编辑
您也可以像这样调用:
Post.find(23).created_at_before_type_cast
发布于 2011-02-20 18:33:19
试一试
Post.find_by_id(23).created_at.to_s
https://stackoverflow.com/questions/5056447
复制相似问题