简体   繁体   中英

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

unexpected end of input

error in my console. It looks like there is a weird query going on in the Rails side. Here is the query from 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.

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 . The problem is that there is another User record with at least the same e-mail address, which is causing the rollback.

You should probably also make sure that you're returning status 422 (Unprocessable Entity) with appropriate errors when an update fails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM