How can I iterate through all of the Models in my rails app?

后端 未结 5 2142
天命终不由人
天命终不由人 2021-02-08 17:51

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|         


        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 18:14

    If you are looking at ApplicationRecord models only in a modern Rails application, you can just use

    ApplicationRecord.descendants
    

    Here you can have a look at it : http://apidock.com/rails/Class/descendants

提交回复
热议问题