使用 Ember-data 和 Rails 编辑模型未保存
Editing model with Ember-data and Rails not saving
我正在尝试使用 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" = 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" = ORDER BY "api_keys"."id" ASC LIMIT 1 [["access_token", "500b9b5d38ecb9f851b89823d5b40d0f"]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT 1 [["id", 2]]
ApiKey Load (0.4ms) SELECT "api_keys".* FROM "api_keys" WHERE "api_keys"."user_id" = 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 会像这样 select !=2。
有验证失败。您正在更新 ID 为 2 的用户,我敢打赌您对 username
和 email
进行了唯一性验证。问题是有另一个 User
记录至少具有相同的电子邮件地址,这导致回滚。
您可能还应该确保在更新失败时返回状态 422 (Unprocessable Entity)
并显示适当的错误。
我正在尝试使用 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" = 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" = ORDER BY "api_keys"."id" ASC LIMIT 1 [["access_token", "500b9b5d38ecb9f851b89823d5b40d0f"]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = LIMIT 1 [["id", 2]]
ApiKey Load (0.4ms) SELECT "api_keys".* FROM "api_keys" WHERE "api_keys"."user_id" = 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 会像这样 select !=2。
有验证失败。您正在更新 ID 为 2 的用户,我敢打赌您对 username
和 email
进行了唯一性验证。问题是有另一个 User
记录至少具有相同的电子邮件地址,这导致回滚。
您可能还应该确保在更新失败时返回状态 422 (Unprocessable Entity)
并显示适当的错误。