Finding all by Polymorphic Type in Rails?
Is there a way to find all Polymorphic models of a specific polymorphic type in Rails? So if I have Group, Event, and Project all with a declaration like: has_many :assignments, :as => :assignable Can I do something like: Assignable.all ...or BuiltInRailsPolymorphicHelper.all("assignable") That would be nice. Edit: ... such that Assignable.all returns [Event, Group, Product] (array of classes) There is no direct method for this. I wrote this monkey patch for ActiveRecord::Base . This will work for any class. class ActiveRecord::Base def self.all_polymorphic_types(name) @poly_hash ||= {}.tap do