Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save a current date/time for a DATETIME column in rails 3?

I have a DATETIME column called last_profile_update. 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.

like image 857
Tamik Soziev Avatar asked Apr 18 '12 15:04

Tamik Soziev


3 Answers

Perhaps a way to simplify that code:

user = User.create(:last_profile_update => Time.now)
like image 118
Brian Underwood Avatar answered Nov 12 '22 18:11

Brian Underwood


It could be done with

user.touch(:last_profile_update)
like image 31
shajin Avatar answered Nov 12 '22 19:11

shajin


Figured it was Time.now

user = User.new
user.last_profile_update = Time.now
user.save
like image 1
Tamik Soziev Avatar answered Nov 12 '22 19:11

Tamik Soziev