0

which is to find out all the Models in the app. This can be found out from the project folders / filenames, or in the route.rb, but just wonder if there is a Ruby way of finding it out on script/console?

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • possible duplicate of [Is there a way to get a collection of all the Models in your Rails app?](http://stackoverflow.com/questions/516579/is-there-a-way-to-get-a-collection-of-all-the-models-in-your-rails-app) – freemanoid May 02 '14 at 14:53

1 Answers1

3

This has come up before.

Is there a way to get a collection of all the Models in your Rails app?

Community
  • 1
  • 1
jdl
  • 17,702
  • 4
  • 51
  • 54
  • hm... that solution either uses file listing in a folder, or looking for subclasses, but won't show the class until the class is actually used before... so they both don't seem a complete solution... must the file system be touched for Rails to know? In other words, Rails have no knowledge of Models in the app until it actually goes to app/models to load the file? – nonopolarity Sep 06 '10 at 15:52
  • 1
    Yes, because Rails autoloads (i.e. lazily-loads) models in the development environment, the file isn't loaded until its class name is referenced somewhere in executed code. This is not the case in production, though. – John Douthat Sep 06 '10 at 20:10