Created
November 8, 2011 13:03
-
-
Save equivalent/1347687 to your computer and use it in GitHub Desktop.
how to get model names of all rails models (works for STI)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Since Rails doesn't load classes unless it needs them, you must read the models from the folder. Here is the code | |
Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file| | |
begin | |
require file | |
rescue | |
end | |
end | |
models = ActiveRecord::Base.subclasses.collect { |type| type.name }.sort | |
models.each do |model| | |
print model | |
print ' ' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://apidock.com/rails/Class/descendants, Rails 5 uses abstract
ApplicationRecord
classOr something like that: