Two activeadmin namespaces

I am trying to install activeadmin with two namespaces in the last 4 hours and I have no luck.

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

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

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

I tried to wrap the whole configuration in the active_admin configuration with namespaces, and I tried to manually create the files, etc., but every time I had problems.

Activeadmin has changed so much over the past year, Iโ€™m afraid that half of the instructions I saw are out of date. And not one of them is complete. The documentation is only partially in the namespace.

Does anyone have step-by-step instructions for installing these two namespaces from start to finish? I would be very grateful for the help in this!

EDIT

When I go to start the server (or in this case I try to use route rails), 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 also tried without a namespace:

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

FYI I added the directory "active_admin" and placed directories with names there. I added both download paths (thanks for that).

Does this error have any connection with the new dashboard pages? I am going to learn how they work further.

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

EDIT IMAGE

Well, in the latest release, I found that removing two directories with the names activeadmin from the "active_admin" directory that I created fixed the problem. I'm not sure that this would not work ... but well, I have spent enough cycles on this problem and am ready to move on.

Hope this helps someone else.

+5
source share
2 answers

Have you added the / admin _unit application to the active_admin download path?

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

This can go to 'config / initializers / active_admin.rb' This is not necessary because active_admin does not require loading resources more than once

As for the authentication method, something like this should work:

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

note that "authentication_method" and "current_user_method" are two different settings (used for authentication before the actions of the controller and for returning the current user, respectively). I am only pointing this out because, I think, "current_user" is a method that (non-activeadmin) Sets the default calls to return a logged in user

+8
source

The directories in which you place the files are different from the namespace configuration. If you want to add a new directory to which Active Admin downloads files from:

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

Now you can put the files in the / admin _unit application, and Active Admin will download them. This does not affect where the "namespace" contains these files.

To set a namespace for a resource, simply pass the namespace name to the registry:

 ActiveAdmin.register SomeResource, :namespace => :admin_unit do # configuration end 
+7
source

Source: https://habr.com/ru/post/1439582/


All Articles