开发者

A bug in rails? About model inherited

开发者 https://www.devze.com 2023-01-12 01:00 出处:网络
My env: ruby-1.9.2-preview3; rails-3.0.0.beta3 class PostFather < ActiveRecord::Base def self.inherited(subclass)
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
开发者_运维问答

In the console:


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

You can try it yourself;


ActiveRecord is using the inherited method, you need to call super so the ActiveRecord stuff still runs:

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

精彩评论

暂无评论...
验证码 换一张
取 消