rails 4 postgis和singular表名

时间:2014-04-11 16:52:31

标签: ruby-on-rails rgeo

我们使用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中查明这个问题:

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'

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

任何建议都表示赞赏。

1 个答案:

答案 0 :(得分:0)

我找到了两个解决方案:

  1. 从模型中删除set_rgeo_factory_for_column,我正在使用默认工厂
  2. 明确指定表名self.table_name。这很奇怪,因为我设置了ActiveRecord :: Base.pluralize_table_names = false