[英]Ember.js Error: No model was found for 'id' while saving record using ember-data
[英]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" = $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這樣的。
有驗證失敗。 您正在更新ID為2的用戶,我敢打賭您對username
和email
具有唯一性驗證。 問題是存在另一個具有至少相同電子郵件地址的User
記錄,這導致了回滾。
當更新失敗時,您可能還應該確保返回帶有適當錯誤的狀態422 (Unprocessable Entity)
不可422 (Unprocessable Entity)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.