Skip to content

Instantly share code, notes, and snippets.

@pgwillia
Created October 24, 2014 22:42
Show Gist options
  • Save pgwillia/46206718b7826897b177 to your computer and use it in GitHub Desktop.
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)
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
@pgwillia
Copy link
Author

'puts ActiveRecord::Base.send(:subclasses)' will print the models derived from ActiveRecord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment