在Rails控制台中查看回滚错误的原因 [英] View cause of rollback error in rails console

查看:56
本文介绍了在Rails控制台中查看回滚错误的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Rails控制台更新记录,并遇到回滚错误:

I'm trying to update a record through the rails console and am getting a rollback error:

Project.find(118).update_attributes(:featured=>true)
  Project Load (2.6ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1  [["id", 118]]
   (2.8ms)  BEGIN
   (1.3ms)  ROLLBACK
=> false

如何查看错误源?我能够更新其他记录的属性,所以我想检查一下为什么该特定记录不起作用。

How can I view the source of the error? I'm able to update the attribute for other records, so I'd like to inspect why this particular record isn't working.

推荐答案

您的 Project 实例可能无效。要查看阻止保存的错误,您可以输入:

Your Project instance is probably invalid. To see what error prevented it from saving, you can type:

project = Project.find 118
project.assign_attributes(featured: true)
project.valid?
project.errors.full_messages

这篇关于在Rails控制台中查看回滚错误的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆