Ruby on rails 特定表的未定义_方法错误

Ruby on rails 特定表的未定义_方法错误,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我目前正在为现有数据库开发一个管理工具,在构建特定表时遇到了一个奇怪的问题 下面是使用rake db:schema:dump的表的模式: create_table "locality", :force => true do |t| t.integer "version", :limit => 8, :null => false t.string "truth_id",

我目前正在为现有数据库开发一个管理工具,在构建特定表时遇到了一个奇怪的问题

下面是使用rake db:schema:dump的表的模式:

create_table "locality", :force => true do |t|
    t.integer "version",             :limit => 8,                  :null => false
    t.string  "truth_id",                                          :null => false
    t.string  "truth_record_id",                                   :null => false
    t.binary  "deleted",             :limit => 1,                  :null => false
    t.string  "internal_code",                                     :null => false
    t.string  "iso_code"
    t.string  "materialized_path",                                 :null => false
    t.string  "invariant_name",                                    :null => false
    t.binary  "published",           :limit => 1,                  :null => false
    t.float   "geo_point_latitude",               :default => 0.0
    t.float   "geo_point_longitude",              :default => 0.0
    t.string  "class",                                             :null => false
    t.integer "hut_count",                        :default => 0
    t.integer "hotel_count",                      :default => 0
    t.string  "destination_url"
  end

 add_index "locality", ["truth_record_id"], :name => "truth_record_id", :unique => true
我使用gem从转储的模式创建脚手架:

rails g scaffold locality version:integer truth_id:string truth_record_id:string
  deleted:binary internal_code:string iso_code:string materialized_path:string 
  invariant_name:string published:binary geo_point_latitude:float 
  geo_point_longitude:float class:string hut_count:integer hotel_count:integer 
  destination_url:string
此工作流适用于许多其他表,但在访问/localities或localities.all时,rails控制台中的所有内容都会:

irb(main):001:0> Locality.all
Locality Load (2.1ms)  SELECT `locality`.* FROM `locality` 
NoMethodError: undefined method `attribute_method_matcher' for "Country":String
“国家”:字符串来自哪里? 起初,我认为模型名“locality”在某种程度上是rails为i18n的东西保留的,但在命名模型“Bla”时也会出现同样的问题


我使用的是rails 3.2.13和MySQL数据库。

我认为您的列:class无效。既然该类已经是ruby中任何对象的方法,您如何访问该列


我认为这是造成混乱的原因。加载区域的class列的值是“Country”,对吗?

因此问题是列名为
class
,ruby显然不喜欢它

此问题中发布的解决方案:

或者更具体地说,在这篇博文中(访问日期:2013年3月25日):

啊,问题出在这里,我想我遗漏了一些明显的东西。