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.
我有一个 Rails 应用程序,它允许用户创建帖子(如博客),我想知道如何添加它的创建日期。怎么能加上呢?
Railstimestamps在编写create_table迁移时提供了该方法,它会自动创建一个created_at和一个updated_at时间戳,并在创建/更新条目时相应地填充它们。
timestamps
create_table
created_at
updated_at
每个 rails 模型都已经有默认created_at列,当第一次保存记录时,该列总是会更新。
post = Post.first puts post.created_at