
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 0.81 KB | hits: 9 | expires: Never
def self_and_descendants_from_active_record#nodoc:
klass = self
classes = [klass]
while klass != klass.base_class
classes << klass = klass.superclass
end
classes
rescue
# OPTIMIZE this rescue is to fix this test: ./test/cases/reflection_test.rb:56:in `test_human_name_for_column'
# Appearantly the method base_class causes some trouble.
# It now works for sure.
[self]
end
def human_name(options = {})
defaults = self_and_descendants_from_active_record.map do |klass|
:"#{klass.name.underscore}"
end
defaults << self.name.humanize
I18n.translate(defaults.shift, {:scope => [:activerecord, :models], :count => 1, :default => defaults}.merge(options))
end