Trouble with Active Admin and Packs: Uninitialized Constant Error in Demo Day Pack

This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.

Message originally sent by slack user U723ZSANS8E

Hi! i was wondering if anyone here has had issues using active admin with packs, or has had success in doing so. I’ve had good progress extracting my code into a pack but i’m struggling with active admin particularly.

given this active admin view in packs/demo_day_pack/app/admin/demo_day_pack/demo_day.rb:

ActiveAdmin.register DemoDayPack::DemoDay do
  index do
    id_column
    actions
  end
end

when running the app it throws

Exiting
/Users/rieg/cs/platanus/tmp/packs-example/packs/demo_day_pack/app/admin/demo_day_pack/demo_day.rb:1:in `<main>': uninitialized constant DemoDayPack::DemoDay (NameError)

ActiveAdmin.register DemoDayPack::DemoDay do

any ideas on what could be a good solution to this? it seems like when active admin initializes, the namespace for the pack exists but the model is not loaded yet

Message originally sent by slack user U723ZSANS8E

oh, and btw i have this ActiveAdmin.application.load_paths += ["packs/demo_day_pack/app/admin"] on an initializer inside the pack, otherwise active admin does not knows about the pack

Message originally sent by slack user U723ZSANS8E

if i remove the load_paths change, the view is not registered and when running rails console and trying to use the model’s methods i get this:

$ bin/rails c
Running via Spring preloader in process 13747
Loading development environment (Rails 6.1.7.3)
[1] pry(main)> DemoDayPack::DemoDay
NameError: uninitialized constant DemoDayPack::DemoDay

ActiveAdmin.register DemoDayPack::DemoDay do
                                ^^^^^^^^^
from /tmp/packs-example/packs/demo_day_pack/app/admin/demo_day_pack/demo_day.rb:1:in `<main>'

Message originally sent by slack user U71TN2WF04X

I manage to make it work adding the following to an initializer:

ActiveAdmin::ApplicationSettings.load_paths << File.expand_path('app/admin', pack.relative_path.to_s)

Message originally sent by slack user U71TN2WF04X

That is inside a loop traversing all packs

Message originally sent by slack user U723ZSANS8E

genio