Sunday, April 28, 2013

Rails Single Table Inheritance With ActiveAdmin and Namespaces

So I stumbled with this for hours, working on a monkey patch for Inherited Resources, finally giving up. Basically, if you use STI with ActiveAdmin, don't use module namespaces. It breaks the shit out of inherited resources.. IH can't deal with the "Name::Class" ::'s, it just borks.. the monkey patch I was working on was to resolve the error when IH tries to use the model name as an instance variable like @Name::Class, which ruby is not interested in trying to do.


So, moral of the story: Don't use namespaced (with modules) STI models with AA, or IH.
~Nic

UPDATE: I was sent this from an anonymous commenter.  Excellent tip:

This actually works if you create a dummy class for your Namespaced model. For example do something like this: ActiveAdmin.register Parent::Child, as "MyClass". And then create a dummy model called MyClass as class MyClass < Parent::Child. This works.
UPDATE: I was sent this as well by another commenter:
This ugly shit works:
ActiveAdmin.register ::MyModule::Base, :as => 'MyModel'


without Dummy models