[英]How do I save a current date/time for a DATETIME column in rails 3?
I have a DATETIME column called last_profile_update.我有一个名为 last_profile_update 的 DATETIME 列。 I need to update it with a current time.
我需要用当前时间更新它。 I have the following code:
我有以下代码:
user = User.new
user.last_profile_update = Date.today
user.save
but it does not work.但它不起作用。
也许是一种简化该代码的方法:
user = User.create(:last_profile_update => Time.now)
可以用
user.touch(:last_profile_update)
Figured it was Time.now
Time.now
是时间。 Time.now
user = User.new
user.last_profile_update = Time.now
user.save
可以通过以下方式完成:
user.last_profile_update = Date.today.to_datetime
User.create({:last_profile_update=>Time.now})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.