There must be some validation which is stopping this user to be saved. Just check your validations in User model. You can also check the errors on this user using u.errors.full_messages.to_sentence
Why am I unable to save an existing user with updated attributes in my rails app?
-
29-06-2022 - |
Domanda
I ran this in a rails console:
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
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow