0

DB中有这样的行(来自模式):

 t.datetime "password_link_sent_at"

和回调:

 self.password_link_sent_at = Time.now

但是输出是错误的:

Started PUT "/email_password" for 127.0.0.1 at 2013-05-22 03:22:42 +0400
Processing by SignsController#email_password as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"10qxpSGYRAKs/SqbWyG2IstRxpIe4VoOT96hNANq9Tk=", "email_reset"=>"user_mail@mail.ru", "commit"=>"Reset Password"}
  User Load (6.0ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'user_mail@mail.ru' LIMIT 1
  User Exists (1.0ms)  SELECT 1 AS one FROM "users" WHERE "users"."password_reset_token" = '2kE2dtwlnsMrnCGTIGuCvQ' LIMIT 1
   (1.0ms)  BEGIN
   (1.0ms)  UPDATE "users" SET "password_reset_token" = '2kE2dtwlnsMrnCGTIGuCvQ', "password_link_sent_at" = '2013-05-21 23:22:43.167461', "updated_at" = '2013-05-21 23:22:43.175461' WHERE "users"."id" = 1
   (5.0ms)  COMMIT
  Rendered user_mailer/password_reset.text.erb (1.0ms)

关注请求时间,关注password_link_sent_at自身,关注更新时间。哪个更早4小时。

4

3 回答 3

2

您大概在 UTC 中将时间存储在数据库中,这是一件好事。

日志设置为本地时间。

通常时间存储为 UTC 并转换为显示目的。这使您的数据库时区中立。

于 2013-05-21T23:33:01.217 回答
0

self.password_link_sent_at = Time.zone.now

在这里查看信息http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html

于 2013-05-22T00:01:02.183 回答
0

我不确定这个,但更改您的应用程序时区设置可能会有所帮助:

在 config/application.rb

config.time_zone = 'Prague'
于 2013-05-22T00:03:34.383 回答