我已经在Heroku上部署了我的Rails应用程序。但是,我无法通过Heroku控制台保存数据库编辑。
如果我想通过控制台更新模型,请执行以下步骤 -
rails console
@doc = Document.find_by_title('Test’)
@doc.status = 1
@doc.save*
然而,在Heroku模型中,保存不起作用
heroku run rails c
@doc = Document.find_by_title('Test’)
@doc.status = 1
@doc.save
控制台输出如下
(1.9ms) BEGIN
(1.9ms) BEGIN
Commontator::Thread Load (1.7ms) SELECT "commontator_threads".* FROM "commontator_threads" WHERE "commontator_threads"."commontable_id" = $1 AND "commontator_threads"."commontable_type" = $2 LIMIT 1 [["commontable_id", 40], ["commontable_type", "Document"]]
Commontator::Thread Load (1.7ms) SELECT "commontator_threads".* FROM "commontator_threads" WHERE "commontator_threads"."commontable_id" = $1 AND "commontator_threads"."commontable_type" = $2 LIMIT 1 [["commontable_id", 40], ["commontable_type", "Document"]]
Approval Load (1.8ms) SELECT "approvals".* FROM "approvals" WHERE "approvals"."document_id" = $1 [["document_id", 40]]
Approval Load (1.8ms) SELECT "approvals".* FROM "approvals" WHERE "approvals"."document_id" = $1 [["document_id", 40]]
Review Load (1.8ms) SELECT "reviews".* FROM "reviews" WHERE "reviews"."document_id" = $1 [["document_id", 40]]
Review Load (1.8ms) SELECT "reviews".* FROM "reviews" WHERE "reviews"."document_id" = $1 [["document_id", 40]]
(2.1ms) ROLLBACK
(2.1ms) ROLLBACK
对于我尝试更新的任何属性,这都是相同的。
有什么想法吗?
答案 0 :(得分:0)
我想我明白了。它受到验证的影响,如果你想保存并跳过验证,那么
@document.update_columns(status: 1)
或
@document.attribute['status'] = 1
@document.save
两者都会跳过验证。
答案 1 :(得分:0)
您也可以试试这个。
heroku run rails c
doc = Document.find_by_title("Test")
doc.status = 1
doc.save(validate: false)