我意识到这可能不是"最佳实践"但这是一种临时修复/实验。我尝试使用rails控制台更新Heroku上的记录,但每当我保存它时它就会回滚。
UserAdmin = User.find_by(email: "User@example.com")
UserAdmin.admin = true
UserAdmin.save
结果是:
(0.6ms) BEGIN
(0.6ms) BEGIN
User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."email") = LOWER('User@example.com') AND "users"."id" != 3) LIMIT 1
User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."email") = LOWER('User@example.com') AND "users"."id" != 3) LIMIT 1
User Exists (0.5ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."user_name") = LOWER('example') AND "users"."id" != 3) LIMIT 1
User Exists (0.5ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."user_name") = LOWER('example') AND "users"."id" != 3) LIMIT 1
(0.4ms) ROLLBACK
(0.4ms) ROLLBACK
我是不是错了?是否有任何特殊原因记录没有保存在Heroku上?
答案 0 :(得分:1)
如果你这样做,你会得到什么:
user_admin = User.find_by(email: "User@example.com")
user_admin.admin = true
user_admin.valid?
user_admin.errors.full_messages
(我意识到这还不是答案,但是以这种方式发布,因为评论太杂乱了。)