Compiling the gist of answers other people have given before:
In the development environment your model classes will not be eager loaded.
Only when you invoke some code that references a model class, the corresponding file will be loaded. (Read up on 'autoloading' for further detail.)
So if you need to do some checks upon startup of the rails server, you can manually invoke
Rails.application.eager_load!
and after that get a list of all model classes with
model_classes = ActiveRecord::Base.descendants
For a list of model names associated with their database tables, you might use
model_classes.map{ |clazz| [clazz.model_name.human, clazz.table_name] }.sort
You can put your code in an arbitrarily named file in the config/initializers
directory. All ruby files in that directory will get loaded at startup in alphabethical order.
The eager loading will of course take some time and thus slow down server and console start-up in the development environment a bit.
Other approaches such as parsing a list of filenames in the app/models
directory are not reliable in more complex Rails applications.
If in a Rake task, make sure your Application is properly initialized before you send eager_load!
. To that end, let your rake task depend on :environment
.
HTH!