0

我们正在使用 rails (4.0.4)、ruby (2.0.0p247) 和 activerecord-postgis-adapter (0.6.5) 以及在 ./config/environment.rb 中设置的单数表名 (ActiveRecord::Base.pluralize_table_names = false)

这在开发和测试环境中非常有用。

在生产环境中,它适用于除一个项目之外的每个表。对于此表,我们在控制器索引中看到错误。

我重新生成了脚手架,并能够在 project_controllers 中查明这个 lin 的问题:

set_rgeo_factory_for_column(:location, RGeo::Geographic.spherical_factory(:srid => 4326))

错误是:

 E, [2014-04-11T10:23:09.543299 #10740] ERROR -- : PG::UndefinedTable: ERROR:  relation "projects" does not exist
LINE 5:                WHERE a.attrelid = '"projects"'::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 = '"projects"'::regclass
             AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

I, [2014-04-11T10:23:09.543625 #10740]  INFO -- : Completed 500 Internal Server Error in 7ms
F, [2014-04-11T10:23:09.545403 #10740] FATAL -- :
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR:  relation "projects" does not exist
LINE 5:                WHERE a.attrelid = '"projects"'::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 = '"projects"'::regclass
             AND a.attnum > 0 AND NOT a.attisdropped
           ORDER BY a.attnum
): app/controllers/projects_controller.rb:11:in `index'

看起来真的很奇怪,它适用于所有其他环境,在生产中它只对一个表以及相关表失败。

任何建议表示赞赏。

4

1 回答 1

0

我找到了两个解决方案:

  1. 从模型中删除 set_rgeo_factory_for_column,无论如何我都在使用默认工厂
  2. 显式指定表名 self.table_name。这很奇怪,因为我设置 ActiveRecord::Base.pluralize_table_names = false
于 2014-04-16T15:56:51.600 回答