1

I am trying to get a list of all models in my app with an already defined Pundit policy.

until then , I am checking it using this code :

current_user = User.first
ActiveRecord::Base.send(:subclasses).map { |subclass| subclass.name if    
    Pundit.policy(current_user, subclass.new) }

but as I am using the Globalize gem, and I get the following error , on collecting , as an abstract class it cannot be instantiated

NotImplementedError: Globalize::ActiveRecord::Translation is an
  abstract class and cannot be instantiated.

Is there anyway to override this error ? inserting some check in the if test before instantiating the subclass I can also remove this Globalise table from the subclass list

["HABTM_Groups", "HABTM_Roles", "HABTM_Groups", "HABTM_Roles", "User", "HABTM_Groups", "HABTM_Roles", "AccessLevel", "Company", "Document", "Group", "Globalize::ActiveRecord::Translation", "HABTM_Users", "Message", "Profile", "RestrictedActivity", "RestrictedAttribute", "Role", "HABTM_Users", "Sheet"]

thanks for feedback

1 Answers1

0

I found how to avoid the abstracts classes ...

ActiveRecord::Base.send(:subclasses).map { |subclass| subclass.name if !subclass.abstract_class? && Pundit.policy(current_user, subclass.new) }.compact

maybe there is a simpler way to get this list using some internal Pundit trick I did not discovered yet