Guest User

Untitled

a guest
Jun 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. def self_and_descendants_from_active_record#nodoc:
  2. klass = self
  3. classes = [klass]
  4. while klass != klass.base_class
  5. classes << klass = klass.superclass
  6. end
  7. classes
  8. rescue
  9. # OPTIMIZE this rescue is to fix this test: ./test/cases/reflection_test.rb:56:in `test_human_name_for_column'
  10. # Appearantly the method base_class causes some trouble.
  11. # It now works for sure.
  12. [self]
  13. end
  14.  
  15.  
  16. def human_name(options = {})
  17. defaults = self_and_descendants_from_active_record.map do |klass|
  18. :"#{klass.name.underscore}"
  19. end
  20. defaults << self.name.humanize
  21. I18n.translate(defaults.shift, {:scope => [:activerecord, :models], :count => 1, :default => defaults}.merge(options))
  22. end
Add Comment
Please, Sign In to add comment