Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Namespaces of activeadmin

I'm trying to install activeadmin with two namespaces for the past 4 hours and am having no luck.

I want two namespaces. "admin" and "admin_unit".

I would assume that I would have the app/admin and app/admin_unit directories.

For the admin namespace, I would like to use the default devise authentication, and for the "admin_unit" namespace, I have a current_user method that I need to use.

I've tried wrapping all the config in the active_admin config with namespaces, and i've tried manually creating the files etc. but every time I have some problem.

Activeadmin has changed so much in the past year, I'm affraid half of the instructions i've seen are outdated. And none of them are complete. The documentation is only partially there on the namespacing.

Does anyone have some step by step instructions on installing these two namespaces from start to finish? I would be very appreciative for some help on this!

EDIT

When I go to start server (or in this case im trying to rake routes), I get this error:

 Expected /app/active_admin/admin/dashboard.rb to define Admin::Dashboard (LoadError)

dashboard.rb has this in it:

ActiveAdmin.register_page "My Page", :namespace => :admin do
  content do
    para "Hello World"
  end
end

I've also tried with no namespace:

ActiveAdmin.register_page "My Page" do
  content do
    para "Hello World"
  end
end

FYI I added a "active_admin" directory, and put both namespaced directories in there. I added both to the loadpaths (thanks for that).

Does this error have anything to do with the new dashboard pages? I am going to look into how those work next.

Thanks guys! Thanks for your work Gregg, I have used AA on dozens of apps now and love it!

EDIT FIX

Ok, on the last issue, I found that taking the two activeadmin namespaced directories out of the "active_admin" directory that I created fixed the problem. Not sure what that wouldn't work... but oh well, i've spent enough cycles on this issue, and am ready to move on.

Hope that helps someone else..

like image 445
Sean Avatar asked Oct 13 '12 21:10

Sean


2 Answers

Did you add app/admin_unit to active_admin's load path?

  config.load_paths = [File.expand_path('app/admin', Rails.root), File.expand_path('app/admin_unit', Rails.root)]

That can go in 'config/initializers/active_admin.rb' This is nessasary because of the way active_admin takes care not to load resources more than once

As for authentication method, something like this should work:

config.namespace :admin_unit do |namespaced|
    namespaced.authentication_method = :current_user
end

note though, that 'authentication_method' and 'current_user_method' are two different devise settings (used to authenticate before controller actions, and to return the current user respectively). I only point this out because, I think 'current_user' is the method that (non-activeadmin)Devise calls by default to return the logged-in user

like image 188
OutlawAndy Avatar answered Sep 27 '22 21:09

OutlawAndy


The directories that you place files in are different than the configuration of namespaces. If you would like to add a new directory that Active Admin loads files from:

  config.load_paths = [File.expand_path('app/admin', Rails.root), File.expand_path('app/admin_unit', Rails.root)]

Now you can place files in app/admin_unit and Active Admin will load them. This has no effect on which "namespace" those files are placed in.

To set the namespace for a resource, simply pass the name of the namespace into the registration:

ActiveAdmin.register SomeResource, :namespace => :admin_unit do
  # configuration
end
like image 33
Greg Bell Avatar answered Sep 27 '22 22:09

Greg Bell