【发布时间】:2011-04-05 00:31:44
【问题描述】:
现在我的课是这样的。
class BalanceName < ActiveRecord
def before_validation
set_blank_attributes_to_nil(@attributes)
end
end
class Balance < ActiveRecord
def before_validation
set_blank_attributes_to_nil(@attributes)
end
end
我想将活动记录继承到一个类中,而不是想将该类继承到其他类中。
我想要这样的东西。
class CommonActiveRecord < ActiveRecord::Base
def before_validation
set_blank_attributes_to_nil(@attributes)
end
end
class BalanceName < CommonActiveRecord
def before_validation
super
end
end
class Balance < CommonActiveRecord
def before_validation
super
end
end
【问题讨论】:
-
@phil 我想创建一个继承 ActiveRecord 的通用类。而我的另一个类将继承该公共类。在我的问题的第二个块中,我编写了一个我想要类似的代码。
标签: ruby-on-rails ruby inheritance activerecord