0

我在 Rails 控制台中运行了这个:

u = User.first
  User Load (0.3ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
 => #<User id: 4, name: "Administrator", email: "administrator@wdis.com", created_at: "2013-09-27 01:01:54", updated_at: "2013-09-29 23:52:11", password_digest: ".......", remember_token: "........", admin: true, num_credits: nil> 
2.0.0p247 :002 > u.num_credits = 1
 => 1 
2.0.0p247 :003 > u.num_credits
 => 1 
2.0.0p247 :004 > u.save
   (0.3ms)  begin transaction
  User Exists (0.3ms)  SELECT 1 AS one FROM "users" WHERE (LOWER("users"."email") = LOWER('administrator@wdis.com') AND "users"."id" != 4) LIMIT 1
   (0.2ms)  rollback transaction
 => false 
4

1 回答 1

1

必须有一些验证阻止此用户被保存。只需在用户模型中检查您的验证。您还可以使用检查此用户的错误u.errors.full_messages.to_sentence

于 2013-10-01T01:51:18.813 回答