铁轨中的一个错误?关于继承的模型

时间:2010-08-14 00:24:15

标签: ruby-on-rails typeerror dup inherited

My env: ruby-1.9.2-preview3; rails-3.0.0.beta3

class PostFather < ActiveRecord::Base
  def self.inherited(subclass)
  end
end

class Post < PostFather
end

在控制台中:


> Post.new # => TypeError: can't dup NilClass
> Post.all # => TypeError: can't dup NilClass
> Post.scoped # => TypeError: can't dup NilClass

你可以亲自尝试一下;

1 个答案:

答案 0 :(得分:1)

ActiveRecord正在使用继承方法,你需要调用super,以便ActiveRecord的东西仍在运行:

class PostFather < ActiveRecord::Base
  def self.inherited(subclass)
    super(subclass)
  end
end