activeadmin的两个命名空间 [英] Two Namespaces of activeadmin

查看:81
本文介绍了activeadmin的两个命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的4个小时中,我试图用两个名称空间安装activeadmin,但运气不佳.

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

我想要两个名称空间. "admin"和"admin_unit".

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

我假设我将拥有app/admin和app/admin_unit目录.

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

对于admin名称空间,我想使用默认的devise身份验证,对于"admin_unit"名称空间,我有一个我需要使用的current_user方法.

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.

我尝试用名称空间将所有配置包装在active_admin配置中,并且尝试手动创建文件等.但是每次遇到问题时.

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在过去一年中发生了很大变化,我不敢相信我所看到的指令中有一半已经过时.而且它们都不是完整的.该文档仅部分位于命名空间上.

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!

编辑

当我去启动服务器(或者在这种情况下,我试图耙路由)时,出现此错误:

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包含以下内容:

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

仅供参考,我添加了一个"active_admin"目录,并在其中放置了两个命名空间目录.我将两者都添加到了加载路径中(谢谢).

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.

谢谢大家!感谢您的工作,格里格(Gregg),我现在已经在许多应用程序上使用了AA,并且很喜欢它!

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

编辑修复

好,在最后一个问题上,我发现从我创建的"active_admin"目录中删除了两个以activeadmin命名的目录,可以解决此问题.不知道什么是行不通的...但是,哦,我已经在这个问题上花了足够的时间,并准备继续前进.

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.

希望对别人有帮助.

推荐答案

您是否将app/admin_unit添加到active_admin的加载路径?

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)]

那可以放在'config/initializers/active_admin.rb'中 这很必要,因为active_admin会注意不要多次加载资源

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

但是请注意,"authentication_method"和"current_user_method"是两个不同的设计设置(分别用于在控制器操作之前进行 authenticate 和用于返回当前用户).我仅指出这一点,因为我认为'current_user'是默认情况下(非活动管理员)Devise调用以返回已登录用户的方法

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

这篇关于activeadmin的两个命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆