我正在尝试将create
方法设为私有/受保护ActiveRecord
模型。我想做这样的事情:
class Product < ActiveRecord::Base
def self.create(options)
private
super(options)
end
end
因此我无法Product.create(...)
。但是,我需要这样做
class Pencil < Product
def self.create(options)
options["category"] = "stationary"
super(options)
end
end
这样我可以执行此操作Pencil.create(...)
。提前谢谢!
答案 0 :(得分:1)
class Product < ActiveRecord::Base
class << self
def create(options)
super(options)
end
private :create
end
end
class Pencil < Product
class << self
def create(options)
options["category"] = "stationary"
super(options)
end
end
end