我有两个控制器
一个被定义为
class Admin::Businesses::DealsController < AdminController
它位于app/controllers/admin/businesses/deals_controller.rb
另一个
class Admin::DealsController < AdminController
位于app/controllers/admin/deals_controller.rb
所有功能都可以在开发环境中找到但是当我推送到heroku并且应用程序加载到生产环境中时它会给我这个错误
/app/app/controllers/businesses/deals_controller.rb:1:in `<top (required)>': superclass mismatch for class DealsController (TypeError)
来自我的routes.rb的相关行看起来像这样
namespace 'admin' do
resources :deals do
end
resources :businesses do
resources :deals, module: "businesses"
end
end
由于控制器的名称相同,为什么它会给我这个错误?还是超级不匹配?我怎样才能解决这个问题。我希望两个控制器用于管理下的一个交易,另一个管理/业务下用于业务特定操作。
尝试在prod env中使用本地运行应用程序时,这是完整的堆栈跟踪 rails s -e production
/home/abid/Projects/vocallocal/app/controllers/admin/businesses/deals_controller.rb:1: warning: toplevel constant Businesses referenced by Admin::Businesses
Exiting
/home/abid/Projects/vocallocal/app/controllers/businesses/deals_controller.rb:1:in `<top (required)>': superclass mismatch for class DealsController (TypeError)
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in `require_or_load'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:313:in `depend_on'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:225:in `require_dependency'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:438:in `each'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:438:in `block in eager_load!'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:436:in `each'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:436:in `eager_load!'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/abid/Projects/vocallocal/config/environment.rb:5:in `<top (required)>'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
from /home/abid/Projects/vocallocal/config.ru:4:in `block in <main>'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/abid/Projects/vocallocal/config.ru:1:in `new'
from /home/abid/Projects/vocallocal/config.ru:1:in `<main>'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/server.rb:46:in `app'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in `start'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:55:in `block in <top (required)>'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
由于
答案 0 :(得分:4)
问题是您的路由中的admin
命名空间与您的类层次结构中的admin
模块冲突。有关导致该特定错误的原因的详细信息很复杂,但在http://code.dblock.org/warning-toplevel-constant-xyz-referenced-adminxyz
最简单的解决方案是将您的admin
之一(可能是类名)重命名为其他任何内容。