简体   繁体   English

使用Ember-data和Rails进行编辑的模型未保存

[英]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的用户,我敢打赌您对usernameemail具有唯一性验证。 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.

相关问题 Ember.js错误:使用ember-data保存记录时未找到'id'的模型 - Ember.js Error: No model was found for 'id' while saving record using ember-data Ember-Data beta 3并且保存了许多关系,并且在Rails中添加了一条记录 - Ember-Data beta 3 and saving hasMany relationships and additonally one record with Rails 我如何显示从Rails后端到Ember前端的数据,而不将其保存在数据库中并且不使用Ember-Data? - How do I display data from Rails backend to Ember frontend without saving it in the database and without using Ember-Data? 使用Ember.js和Ember-data&Rails创建记录并处理记录列表 - creating a record with Ember.js & Ember-data & Rails and handling list of records Ember,Ember-data和Rails关系错误:“无法读取未定义的属性'typeKey'” - Ember, Ember-data and Rails relations error: “Cannot read property 'typeKey' of undefined” 具有嵌入式ID和侧载的Ember-Data和Active Model Serializer的has_many配置 - has_many configuration for Ember-Data and Active Model Serializers with embedded IDs and sideloading 型号不适用于新的Ember数据升级 - Models not working with the new Ember-data upgrade 通知余烬数据有关服务器的更改 - Inform ember-data about server changes 单一数据持久性与余烬数据 - Single record persistence with ember-data Ember-data和MongoDB,如何处理_id - Ember-data and MongoDB, how to handle _id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM