I have a whole bunch of child classes that inherit from a parent class via single-table-inheritance in my Rails app. I\'d like a way to get an array of all the child classes tha
In your config/environments/development.rb
Rails.application.configure do
config.eager_load = false
end
U can change false to true, and then in your console to do
Class.subclasses
or
Class. descendants
here is the difference between subclasses and descendants
subclasses:
class Foo; end
class Bar < Foo; end
class Baz < Bar; end
Foo.subclasses # => [Bar]
descendants:
class C; end
C.descendants # => []
class B < C; end
C.descendants # => [B]
class A < B; end
C.descendants # => [B, A]
class D < C; end
C.descendants # => [B, A, D]