0

我在扩展 spree 控制器时遇到问题。当我覆盖控制器时,我无法访问 Order 类。我收到以下错误(我使用spree 1.2.4):

NameError (uninitialized constant Spree::Admin::OrdersController::Order):
spree_russian_post/app/controllers/admin/orders_controller_decorator.rb:9:in `sample_method'
actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
...

问题出在我的控制器中:

spree_russian_post/app/controllers/admi /orders_controller_decorator.rb

这是代码:

require 'spree_core'

Spree::Admin::OrdersController.class_eval do

  def sample_method
      @order = Order.find_by_param(params[:id]) #Here I get the error
      ....
  end

end

我应该怎么做才能访问 Order 类?

4

1 回答 1

2

您的问题是 Spree 认为您正在寻找常数Spree::Admin::OrdersController::Order

将您的查询更改为@order = Spree::Order.find(params[:id])

Spree 然后会知道您正在寻找与 spree_orders 表关联的 spree 对象

于 2013-12-20T18:53:44.610 回答