【问题标题】:Rails update_attribute does not work on production environmentRails update_attribute 不适用于生产环境
【发布时间】:2018-12-15 15:19:53
【问题描述】:

生产日志:

irb(main):036:0> People.find(7).update_attribute(:all_read,[2,3])
  People Load (1.2ms)  SELECT  "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1  [["id", 7]]
  People Load (1.2ms)  SELECT  "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1  [["id", 7]]
   (0.7ms)  BEGIN
   (0.7ms)  BEGIN
   (0.7ms)  COMMIT
   (0.7ms)  COMMIT
  People Store (29.1ms)  {"id":7}
  People Store (29.1ms)  {"id":7}
=> true
irb(main):037:0> People.find(7).all_read
  People Load (1.0ms)  SELECT  "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1  [["id", 7]]
  People Load (1.0ms)  SELECT  "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1  [["id", 7]]
=> []

这在本地工作得很好,但在 heroku 上不起作用。 我在本地使用 sqlite3,在 heroku 上使用 postgresql。

其他相关代码:

class People < ActiveRecord::Base
  serialize :all_read, Array

schema.db
  create_table "people", force: :cascade do |t|
    ...
    t.string   "all_read",            default: "--- []\n"
  end

【问题讨论】:

  • 生产日志上有什么?
  • 为什么要投反对票???
  • 在没有提供建议的情况下投反对票是没有意义的。

标签: ruby-on-rails postgresql heroku


【解决方案1】:

您应该检查您的数据库版本。 还要检查小组开发和生产中的 gem 版本。

我没有在您的日志中看到更新查询。

【讨论】:

    【解决方案2】:

    sqlite 和 postgres 非常不同 开发时使用相同的数据库

    例如,postgres 中的 varchar 是指定长度的字符串,而在 sqlite 中是无限的。

    如果您想在 update_attribute 调用之后找出确切的问题 .errors 方法(使用 byebug 或 logger)来查看问题

    【讨论】:

      猜你喜欢
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 2012-06-05
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      • 2021-02-08
      相关资源
      最近更新 更多