0

这让我快疯了。我测试了在开发和登台环境中更新用户的电子邮件地址,一切正常。它更新 unconfirmed_email 字段并发送确认电子邮件地址。

但是,只有在生产环境中,它才会失败!

在开发/登台环境中,当用户更新他/她的电子邮件地址时,我会看到以下语句。

User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
Profile Load (0.3ms)  SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = 2 LIMIT 1
(0.1ms)  BEGIN
User Exists (0.6ms)  SELECT 1 FROM "users" WHERE ("users"."email" = 'aaaa@yahoo.com' AND "users"."id" != 2) LIMIT 1
(0.3ms)  UPDATE "users" SET "unconfirmed_email" = 'aaaa@yahoo.com', "updated_at" = '2012-08-27 04:22:10.470329' WHERE "users"."id" = 2
User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'jUcfXqMqDjeEsJ3TEKws' LIMIT 1
(0.3ms)  UPDATE "users" SET "unconfirmed_email" = 'aaaa@yahoo.com', "updated_at" = '2012-08-27 04:22:10.470329', "confirmation_token" = 'jUcfXqMqDjeEsJ3TEKws', "confirmation_sent_at" = '2012-08-27 04:22:10.473264' WHERE "users"."id" = 2

但是,在生产中,我看到以下内容。

User Load (6.7ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 5 LIMIT 1
Profile Load (2.1ms)  SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = 5 LIMIT 1
 (1.2ms)  BEGIN
User Exists (1.3ms)  SELECT 1 FROM "users" WHERE ("users"."email" = 'aaaa@yahoo.com' AND "users"."id" != 5) LIMIT 1
 (1.2ms)  ROLLBACK

还有一件奇怪的事情。我可以在 Rails 控制台中手动更新电子邮件地址.....

1.9.3p194 :005 > u.update_attributes(:email => "aaaa@yahoo.com")
(1.3ms)  BEGIN
User Exists (1.4ms)  SELECT 1 FROM "users" WHERE ("users"."email" = 'aaaa@yahoo.com' AND "users"."id" != 1) LIMIT 1
(1.4ms)  UPDATE "users" SET "unconfirmed_email" = 'aaaa@yahoo.com', "updated_at" = '2012-08-27 05:05:26.337961' WHERE "users"."id" = 1
User Load (1.4ms)  SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'Yyg98zno81adJt4mp7pG' LIMIT 1
(1.4ms)  UPDATE "users" SET "unconfirmed_email" = 'aaaa@yahoo.com', "updated_at" = '2012-08-27 05:05:26.337961', "confirmation_token" = 'Yyg98zno81adJt4mp7pG', "confirmation_sent_at" = '2012-08-27 05:05:26.342299' WHERE "users"."id" = 1
Profile Load (1.4ms)  SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = 1 LIMIT 1
(1.7ms)  COMMIT
=> true 

任何帮助将非常感激!

谢谢,

4

1 回答 1

1

我试图弄清楚这两种环境之间的区别 - 开发/登台与生产。由于登台和生产具有几乎相同的设置,我唯一能想到的就是缓存。因此,我将 update_attributes 行更改为以下内容,并且它起作用了。

  if @user.reload.update_attributes(:email => params[:email])
于 2012-08-27T06:24:22.277 回答