[英]Editing model with Ember-data and Rails not saving
I am attempting to edit a user with ember-data and rails, when I edit the user information and try to do a model.save() I get a 我正在尝试使用ember-data和rails编辑用户,当我编辑用户信息并尝试执行model.save()时,我得到了一个
unexpected end of input
error in my console. 我的控制台错误。 It looks like there is a weird query going on in the Rails side. 看起来在Rails端正在进行一个奇怪的查询。 Here is the query from 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
I can't figure why Rails would be trying to select !=2 like this. 我不知道为什么Rails会试图选择!= 2这样的。
There are validations that are failing. 有验证失败。 You're updating the User with id 2, and I'm betting that you have uniqueness validations on username
and email
. 您正在更新ID为2的用户,我敢打赌您对username
和email
具有唯一性验证。 The problem is that there is another User
record with at least the same e-mail address, which is causing the rollback. 问题是存在另一个具有至少相同电子邮件地址的User
记录,这导致了回滚。
You should probably also make sure that you're returning status 422 (Unprocessable Entity)
with appropriate errors when an update fails. 当更新失败时,您可能还应该确保返回带有适当错误的状态422 (Unprocessable Entity)
不可422 (Unprocessable Entity)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.