Created
October 24, 2014 22:42
-
-
Save pgwillia/46206718b7826897b177 to your computer and use it in GitHub Desktop.
List all the models in your Rails app from rails console. Doesn't work for 4.1.4)
This file contains 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
def load_models_in_development | |
if Rails.env == "development" | |
load_models_for(Rails.root) | |
Rails.application.railties.engines.each do |r| | |
load_models_for(r.root) | |
end | |
end | |
end | |
def load_models_for(root) | |
Dir.glob("#{root}/**/app/*models/**/*.rb") do |model_path| | |
begin | |
require model_path | |
rescue | |
# ignore | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'puts ActiveRecord::Base.send(:subclasses)' will print the models derived from ActiveRecord