views:

58

answers:

1

The method to walk through apps/models and look into each file for classes is not what I'm looking for

A: 

Yes you can: http://stackoverflow.com/questions/516579/is-there-a-way-to-get-a-collection-of-all-the-models-in-your-rails-app/516605#516605

For example:

Module.constants.select do |constant_name|
  constant = eval constant_name
  if not constant.nil? and constant.is_a? Class and constant.superclass == ActiveRecord::Base
    constant
  end
end
Jonas Elfström
There's no such a way that I asked for among listed in there. Some do work properly, some don't. And no suitable method for my case.
MG
What's wrong with the example above?
Jonas Elfström
This method most of all looks like a needed answer. But when I tried it on my project, it returned just a few of its models. I did not dive deep into why that's so.
MG
It could be that you actually have to instantiate the model and that would be a bummer. Can't test that theory right now.
Jonas Elfström
This method also returns just a couple of models either from within a console or from within a view. Even more, it returns different sets of models from different views. That means that you're right -- the returned models list depends on context. The question turned out to be not so simple...
MG