开发者

Having trouble saving a datetime in Rails 3 app that has mysql database

I want to save the last date that a token is reset. I can't seem to get it to work.

  1. I changed the field from a date attribute to datetime in a migration and used DateTime.now and that didn't work
  2. I dropped the column and added it back, and that didn't work.
  3. 开发者_开发技巧I added strftime formatting to match datetime format used in the database and that didn't work. I tried changing to Time.now and that didn't work... darn... just figured this out... attributes accessible. Nuts!

current code:

if current_user.token_date.nil?
  current_user.update_attributes(:token_date => Time.now)      
elsif Time.now - current_user.token_date > 1300000 #approx 15 days
  current_user.reset_authentication_token!
  current_user.update_attributes(:token_date => Time.now)
  flash[:notice] = "For your security we just..."
end

Thanks for your help.


token_date has to be a DateTime attribute.

Then just add

current_user.update_attributes(:token_date => DateTime.now)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜