chaadow/active_record-acts_as

getting a list of all models that act_as a model

apaleslimghost opened this issue · 2 comments

i want to provide a single form for creating records of any type that inherits from my base model. is there a way to find all the models that inherit from it so i can provide a dropdown?

Try ActiveRecord::Base.descendants.select { _1.respond_to? :acting_as_model } (untested)

In dev env you might need to call Zeitwerk::Loader.eager_load_all first to load all your models.

thanks @manuelmeurer! for my usecase i've ended up using postgres JSON columns instead, but that solution looks like it'd work (i'd have needed to add and _1.acting_as_model == Card because i had multiple actable models)