ActiveAdmin中此命名空间配置有什么问题?

时间:2012-02-18 03:13:45

标签: ruby-on-rails ruby-on-rails-3.1 activeadmin

我在ActiveAdmin中遇到了命名空间问题。如果我将配置设置添加到初始化程序中的命名空间,我会在尝试启动webrick时捕获一个长异常列表。

我有以下结构:

▾ app/
  ▾ admin/
      agents.rb
      dashboards.rb
  ▾ agency/
      agents.rb
      dashboards.rb

我没有看到在仪表板中设置命名空间的方法,因此现在它们基本上都是:

ActiveAdmin::Dashboards.build do
end

代理商具有以下声明:

ActiveAdmin.register Agent, :namespace=>:agency_admin do

ActiveAdmin.register Agent, :namespace=>:admin do

这一切都可以正常使用默认配置。我可以拉/ agency_admin / agents或/ admin / agents就好了。但是,只要我添加一个配置,例如在初始化程序中作为示例注释掉的内容:

   config.namespace :admin do |admin|
     admin.site_title = "Custom Admin Title"
   end

启动服务器时,我收到了附加的异常流。我很感激这方面的任何/所有帮助。

顺便说一句,我这样做的原因是为每个命名空间提供不同的设计方法。从我在源代码中可以看出,当base_controller从命名空间获取该信息时,可以这样做(至少在当前主服务器上是什么)。我意识到很多人建议使用CanCan,但这不是我想要的,也不是我能做到的。

提前再次感谢!

/Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/namespace.rb:191:in `eval': undefined method `devise' for #<Class:0x000001063e9188> (NoMethodError)
  from /Users/chance/code/rails/nokr/app/models/user.rb:36:in `<class:User>'
  from /Users/chance/code/rails/nokr/app/models/user.rb:1:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:456:in `load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:456:in `block in load_file'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:455:in `load_file'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:342:in `require_or_load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:489:in `load_missing_constant'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in `block in const_missing'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `each'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `const_missing'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing'
  from /Users/chance/code/rails/nokr/app/helpers/user/addresses_helper.rb:1:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:456:in `load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:456:in `block in load_file'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:455:in `load_file'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:342:in `require_or_load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:302:in `depend_on'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:214:in `require_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/helpers.rb:135:in `block in modules_for_helpers'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/helpers.rb:131:in `map!'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/helpers.rb:131:in `modules_for_helpers'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/action_controller/metal/helpers.rb:89:in `modules_for_helpers'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/abstract_controller/helpers.rb:95:in `helper'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/action_controller/railties/paths.rb:17:in `block (2 levels) in with'
  from /Users/chance/code/rails/nokr/app/controllers/application_controller.rb:1:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:456:in `load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:456:in `block in load_file'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:455:in `load_file'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:342:in `require_or_load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:489:in `load_missing_constant'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in `block in const_missing'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `each'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `const_missing'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/inherited_resources-1.2.2/lib/inherited_resources/base.rb:14:in `<module:InheritedResources>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/inherited_resources-1.2.2/lib/inherited_resources/base.rb:4:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/base_controller/menu.rb:2:in `<module:ActiveAdmin>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/base_controller/menu.rb:1:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `block in require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `block in load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/base_controller.rb:2:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/resource_controller/actions.rb:2:in `<module:ActiveAdmin>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/resource_controller/actions.rb:1:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `block in require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `block in load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/resource_controller.rb:2:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/dashboards/dashboard_controller.rb:3:in `<module:Dashboards>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/dashboards/dashboard_controller.rb:2:in `<module:ActiveAdmin>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/dashboards/dashboard_controller.rb:1:in `<top (required)>'
  from (eval):1:in `generate_dashboard_controller'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/namespace.rb:191:in `eval'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/namespace.rb:191:in `generate_dashboard_controller'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/namespace.rb:43:in `initialize'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/application.rb:110:in `new'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin/application.rb:110:in `find_or_create_namespace'
  from /Users/chance/code/rails/nokr/config/initializers/active_admin.rb:39:in `block in <top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/active_admin-bbdbadafe5d7/lib/active_admin.rb:70:in `setup'
  from /Users/chance/code/rails/nokr/config/initializers/active_admin.rb:1:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `block in load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `block in load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:556:in `block (2 levels) in <class:Engine>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:555:in `each'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:555:in `block in <class:Engine>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
  from /Users/chance/code/rails/nokr/config/environment.rb:5:in `<top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `block in require'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `block in load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
  from /Users/chance/code/rails/nokr/config.ru:4:in `block in <main>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rack-1.3.3/lib/rack/builder.rb:51:in `instance_eval'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rack-1.3.3/lib/rack/builder.rb:51:in `initialize'
  from /Users/chance/code/rails/nokr/config.ru:1:in `new'
  from /Users/chance/code/rails/nokr/config.ru:1:in `<main>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rack-1.3.3/lib/rack/builder.rb:40:in `eval'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rack-1.3.3/lib/rack/builder.rb:40:in `parse_file'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rack-1.3.3/lib/rack/server.rb:200:in `app'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands/server.rb:46:in `app'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rack-1.3.3/lib/rack/server.rb:301:in `wrapped_app'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/rack-1.3.3/lib/rack/server.rb:252:in `start'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands/server.rb:70:in `start'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:54:in `block in <top (required)>'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:49:in `tap'
  from /Users/chance/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:49:in `<top (required)>'
  from script/rails:6:in `require'

1 个答案:

答案 0 :(得分:0)

这是初始化程序的操作顺序。 Rails根据字母顺序加载初始值设定项而不是gem deleration(这是我原先的想法)。

无论出于何种原因,一旦我引入了配置选项,它就会尝试加载/解析User对象(一个不是admin_user的设计模型),并且因为Devise尚未初始化而爆炸。

将initializers / active_admin.rb更改为initializers / x_active_admin.rb解决了这个问题。