我正在尝试使用ember-data和rails编辑用户,当我编辑用户信息并尝试做一个model.save()时,我得到了一个
unexpected end of input
我的控制台出现错误。 看起来Rails方面有一个奇怪的查询。以下是Rails的查询:
Started PUT "/users/2" for ::1 at 2015-04-11 15:59:17 -0500
Processing by UsersController#update as HTML
Parameters: {"user"=>{"username"=>"adminUser", "email"=>"admin@test.com", "password"=>"[FILTERED]", "admin"=>true}, "id"=>"2"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 2]]
ApiKey Load (0.4ms) SELECT "api_keys".* FROM "api_keys" WHERE (expired_at >= '2015-04-11 20:59:17.113883') AND "api_keys"."access_token" = $1 ORDER BY "api_keys"."id" ASC LIMIT 1 [["access_token", "500b9b5d38ecb9f851b89823d5b40d0f"]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 2]]
ApiKey Load (0.4ms) SELECT "api_keys".* FROM "api_keys" WHERE "api_keys"."user_id" = $1 AND (expired_at >= '2015-04-11 20:59:17.117827') ORDER BY "api_keys"."id" ASC LIMIT 1 [["user_id", 2]]
(0.2ms) BEGIN
User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."username") = LOWER('adminUser') AND "users"."id" != 2) LIMIT 1
User Exists (0.3ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."email") = LOWER('admin@test.com') AND "users"."id" != 2) LIMIT 1
(0.2ms) ROLLBACK
我无法理解为什么Rails会尝试选择!= 2就像这样。
答案 0 :(得分:1)
有些验证失败了。您正在更新ID为2的用户,我打赌您在username
和email
上拥有唯一性验证。问题是还有另一条User
记录,其中至少有相同的电子邮件地址,导致回滚。
您可能还应该确保在更新失败时返回状态422 (Unprocessable Entity)
并出现相应的错误。