I want to save the last date that a token is reset. I can't seem to get it to work.
- I changed the field from a date attribute to datetime in a migration and used DateTime.now and that didn't work
- I dropped the column and added it back, and that didn't work.
- 开发者_开发技巧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)
精彩评论