0
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

你可以自己试试;

4

1 回答 1

1

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

class PostFather < ActiveRecord::Base
  def self.inherited(subclass)
    super(subclass)
  end
end
于 2010-08-14T00:42:40.590 回答