This error is raised because the column 'type' is reserved for storing the class in case of inheritance

ruby中,使用activerecord生产的数据访问类,结果出现如标题的错误
“This error is raised because the column 'type' is reserved for storing the class in case of inheritance”

google了下,原来是表中有type这个字段,而type应该是被ruby或者是activerecord作为一个保留字之类的,所以出现这个错误

需要的做法是,给改个别名来访问

Code
class Rdevice < ActiveRecord::Base
 set_table_name 
"devices"
 set_inheritance_column :ruby_type

 
# getter for the "type" column
 def device_type
  self[:type]
 end

 
# setter for the "type" column
 def device_type=(s)
  self[:type] 
= s
 end
end

这样基本可以搞定

原文地址:https://www.cnblogs.com/forward/p/1586170.html