1

环境:Rails 3.2.11

添加了 paper_trail 宝石。

请注意,我已经使用了那个 gem,我从来没有遇到过问题,但是这次我遇到了一个错误,我找不到原因。

在我的模型中:

class User < ActiveRecord::Base
  has_paper_trail :versions => :paper_trail_versions
  ...
end

错误:

  User Exists (0.6ms)  SELECT 1 AS one FROM "users" WHERE ("users"."pseudo" = 'joel' AND "users"."id" != 21) LIMIT 1
PG::Error: ERROR:  relation "versions" does not exist
LINE 5:              WHERE a.attrelid = '"versions"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"versions"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

   (0.1ms)  ROLLBACK
Completed 500 Internal Server Error in 28ms

ActiveRecord::StatementInvalid (PG::Error: ERROR:  relation "versions" does not exist
LINE 5:              WHERE a.attrelid = '"versions"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"versions"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
)

有关如何解决此问题的任何线索?

4

1 回答 1

2

您是否按照安装说明进行操作:

通过 Gemfile 将 PaperTrail 安装为 gem:

gem 'paper_trail', '~> 2'

生成一个迁移,它将向您的数据库添加一个版本表。

bundle exec rails generate paper_trail:install

运行迁移。

bundle exec rake db:migrate

将 has_paper_trail 添加到您要跟踪的模型中。

来自https://github.com/airblade/paper_trail

于 2013-07-16T22:59:34.220 回答