为什么我的装饰器会得到未初始化的常量 Spree::Admin::CheckoutsController (NameError)?

Why do I get uninitialized constant Spree::Admin::CheckoutsController (NameError) for my decorator?

我有一个看起来像这样的现有装饰器:

app/controllers/products_controller_decorator.rb

  1 module Spree
  2   Admin::ProductsController.class_eval do
  3     def update_stock_location
            # my custom code

^ 有效。

但是当我试图为 CheckoutsController 创建一个新的装饰器时,我得到了这个错误:

app/controllers/checkouts_controller_decorator.rb:2:in 
`<module:Spree>': uninitialized constant Spree::Admin::CheckoutsController (NameError)
        from /Users/martins/Work/SolidusApp/app/controllers/checkouts_controller_decorator.rb:1:in `<top (required)>'
        from /Users/martins/.rvm/gems/ruby-2.2.3@solidus/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
        from /Users/martins/.rvm/gems/ruby-2.2.3@solidus/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
        from /Users/martins/Work/SolidusApp/config/application.rb:24:in `block (2 levels) in <class:Application>'

这是我的 Spree::Admin::CheckoutsController 的样子: app/controllers/checkouts_controller_decorator.rb

  1 module Spree
  2   Admin::CheckoutsController.class_eval do
  3
  4     def complete
            # my custom code

我不明白为什么它会得到 uninitialized constant Spree::Admin::CheckoutsController (NameError)。这些文件看起来和我一模一样。

这是原文class:

solidus/api/app/controllers/spree/api/checkouts_controller.rb

  1 module Spree
  2   module Api
  3     class CheckoutsController < Spree::Api::BaseController

你想要 Api::CheckoutsController 而不是 Admin::CheckoutsController

module Spree
  Api::CheckoutsController.class_eval do
    # ...

其他找到这个答案的人可能正在寻找Admin::CheckoutController(单数,结帐后没有's')