Rails模型不继承自ActiveRecord :: Base

时间:2016-09-26 16:00:31

标签: ruby-on-rails postgresql activerecord

我刚刚从Rails迁移中创建了两个表。一个用于ShippingLabel,另一个用于名为Shippo的模型。迁移成功运行,它在Postgres中正确创建了一个表,它甚至看起来像是将Shippo识别为常量。但是,它不会像对待Shippo那样继承ActiveRecord :: Base。

shippo.rb

class Shippo < ActiveRecord::Base
end

shipping_label.rb

class ShippingLabel < ActiveRecord::Base

  belongs_to :device_purchase

end

当我运行ShippingLabel < ActiveRecord::Base时,我得到true。当我在控制台中运行Shippo < ActiveRecord::Base时,我得到nil

1 个答案:

答案 0 :(得分:0)

我通常在对象的实例上使用class.superclass来确定超类。

在Rails控制台中:

shippo = Shippo.new #shippo is an instance of the class Shippo
shippo.class.superclass