How can I iterate through all of the Models in my rails app?
问题 I would like to be able to iterate over and inspect all the models in my rails app. In pseudo-code it would look something like: rails_env.models.each do |model| associations = model.reflect_on_all_associations(:has_many) ... do some stuff end My question is how do I inspect my rails app to get a collection of the models (rails_env.models) ? 回答1: Similar to nathanvda's response, use camelize rather than capitalize to support model files with underscores, and use String#constantize rather than