Reputation: 43
So to get a record in the User model I run
@user = User.find(1)
Then to change an attribute:
@user.active = false
It then returns false
When I run
@user.save
I get
(0.2ms) BEGIN
(0.3ms) SELECT 1 FROM `users` WHERE (LOWER(`users`.`username`) = LOWER('sean') AND `users`.`id` != 1) LIMIT 1
(0.3ms) SELECT 1 FROM `users` WHERE (LOWER(`users`.`email`) = LOWER('[email protected]') AND `users`.`id` != 1) LIMIT 1
(0.6ms) ROLLBACK
=> false
Upvotes: 4
Views: 8944
Reputation: 994
Had the same issue. Doing this managed to solve it:
@user.save(validate: false)
Here is the link to original answer: How to skip validations as admin during update_attributes?
Upvotes: 3
Reputation: 12273
Try this to see if errors are being thrown
@user.save!
If your @user.save
is returning false then it means there's an error and something is preventing it from being saved. You can use @user.errors
at that point to see what the errors are.
Upvotes: 17