Hi,
Does anybody know how to enumerate all models (from a controller) ?
Thanks
Hi,
Does anybody know how to enumerate all models (from a controller) ?
Thanks
You could try something like
Dir[RAILS_ROOT + ‘/app/models/*.rb’].each { |file| require file }
This ensures that all models are loaded. Then you should be able to
use something like.
models = ActiveRecord::Base.send(subclasses)
models.each {}
Note, this is untested and therefore may not work.
Chris
Chris R. wrote:
You could try something like
Dir[RAILS_ROOT + ‘/app/models/*.rb’].each { |file| require file }
This ensures that all models are loaded. Then you should be able to
use something like.models = ActiveRecord::Base.send(subclasses)
models.each {}Note, this is untested and therefore may not work.
Chris
This is what I was doing, but I thought there is also a way from
ActiveRecord::Base
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs