Ruby on rails 活动记录回调抛出“;“未定义的方法”;使用STI的类在生产中出错

Ruby on rails 活动记录回调抛出“;“未定义的方法”;使用STI的类在生产中出错,ruby-on-rails,passenger,Ruby On Rails,Passenger,在我的应用程序中,我有许多实例使用单表继承,并且在我的开发环境中一切正常。但当我发布到生产(使用passenger)时,我得到以下错误: InventoryOrder:类的未定义方法“保存前” (命名者) 为什么这可以在我的开发环境中工作,而不能在生产环境中工作?两者都使用Rails 4.2和Ruby 2.1.5。这可能是乘客的问题吗 以下是InventoryOrder类: class InventoryOrder < Order def self.model_name

在我的应用程序中,我有许多实例使用单表继承,并且在我的开发环境中一切正常。但当我发布到生产(使用passenger)时,我得到以下错误:

InventoryOrder:类的未定义方法“保存前” (命名者)

为什么这可以在我的开发环境中工作,而不能在生产环境中工作?两者都使用Rails 4.2和Ruby 2.1.5。这可能是乘客的问题吗

以下是InventoryOrder类:

class InventoryOrder < Order

    def self.model_name
        Order.model_name
    end

    before_save :ensure_only_feed_types

    def ensure_only_feed_types
        order_products.each do |op|
            if !ProductTypes::is_mix?(op.product_type.type)
                raise Exceptions::FailedValidations, _("Can't have an inventory order for anything but mixes")
            end
        end
    end

    def self.check_if_replenishment_order_is_needed(product_type_id)

        prod_type = ProductType.find(product_type_id)

        return if prod_type.nil? || prod_type.min_system_should_have_on_hand.nil? || prod_type.min_system_should_have_on_hand == 0                

        amount_free = Inventory::inventory_free_for_type(product_type_id)

        if prod_type.min_system_should_have_on_hand > amount_free
            if prod_type.is_mix?
                InventoryOrder::create_replenishment_order(product_type_id, prod_type.min_system_should_have_on_hand - amount_free)
            else
                OrderMoreNotification.create({subject: "Running low on #{prod_type.name}", body: "Should have #{prod_type.min_system_should_have_on_hand} of unreserved #{prod_type.name} but only #{amount_free} is left"})
            end
        end

    end

    def self.create_replenishment_order(product_type_id, amount)

        # first check for current inventory orders
        orders = InventoryOrder.joins(:order_products).where("order_products.product_type_id = ? and status <> ? and status <> ?", product_type_id, OrderStatuses::ready[:id], OrderStatuses::completed[:id])

        amount_in_current_orders = orders.map {|o| o.order_products.map {|op| op.amount }.sum }.sum
        amount_left_to_add = amount - amount_in_current_orders

        if amount_left_to_add > 0
            InventoryOrder.create({pickup_time: 3.days.from_now, location_id: Location::get_default_location.id, order_products: [OrderProduct.new({product_type_id: product_type_id, amount: amount_left_to_add})]})
        end     

    end

    def self.create_order_from_cancelled_order_product(order_product)
        InventoryOrder.create({
            pickup_time: DateTime.now.change({ min: 0, sec: 0 }) + 1.days,
            location_id: Location::get_default_location.id,
            order_products: [OrderProduct.new({
                product_type_id: order_product.product_type_id,
                feed_mill_job_id: order_product.feed_mill_job_id,
                ration_id: order_product.ration_id,
                amount: order_product.amount
              })],
            description: "Client Order for #{order_product.amount}kg of #{order_product.product_type.name} was cancelled after the feed mill job started."
        })
    end

end
class InventoryOrder自由数量\u
如果产品类型为混合型?
库存订单::创建补货订单(产品类型id、产品类型min系统应该有库存-无库存)
其他的
创建({subject:{prod_type.name}上运行不足,{prod_type.name}),body:“应该有{prod_type.min_系统{u应该有}个无保留的{prod_type.name},但只剩下{amount free})
结束
结束
结束
定义自我。创建补充订单(产品类型、id、金额)
#首先检查当前库存订单
orders=InventoryOrder.joins(:order\u products)。其中(“order\u products.product\u type\u id=?和状态?和状态?”,product\u type\u id,OrderStatuses::ready[:id],OrderStatuses::completed[:id])
当前订单中的金额=orders.map{{o|o.order_products.map{op}op.amount}.sum}.sum
剩余金额添加=金额-当前订单中的金额
如果剩余金额添加>0
InventoryOrder.create({Picking_time:3.days.from_now,location_id:location::get_default_location.id,order_products:[OrderProduct.new({product_type_id:product_type_id,amount:amount_left_to_add})])
结束
结束
定义自我。从已取消的订单产品(订单产品)创建订单
InventoryOrder.create({
拾取时间:DateTime.now.change({min:0,sec:0})+1.5天,
location\u id:location::get\u default\u location.id,
订单产品:[OrderProduct.new]({
产品类型标识:订单产品类型标识,
饲料工厂作业id:订单产品。饲料工厂作业id,
配给标识:订单、产品、配给标识,
金额:订单金额
})],
描述:“在饲料厂作业开始后,客户对#{Order_product.amount}kg#{Order_product.product_type.name}的订单被取消。”
})
结束
结束
这是它的父类:

class Order < ActiveRecord::Base
  #active record concerns
  include OrderProcessingInfo

  belongs_to :client
  belongs_to :location
  has_many :order_products
  before_destroy :clear_order_products

  after_save :after_order_saved
  before_save :on_before_save

  accepts_nested_attributes_for :order_products, allow_destroy: true

  after_initialize :init #used to set default values  

  validate :client_order_validations

  def client_order_validations
    if self.type == OrderTypes::client[:id] && self.client_id.nil?
      errors.add(:client_id, _("choose a client"))
    end

  end  
...

end
类顺序
谢谢,
Eric

在进一步挖掘之后,在Roman的评论的帮助下,我发现这个问题是因为我使用了一个旧的ActiveRecord::Concerns约定,该约定在windows上运行良好,但在基于unix的系统上运行不好

根据您的需求,您可以这样定义您的关注点:

module OrderProcessingInfo
  extend ActiveSupport::Concern

  included do

  end
end
在../models/concerns/order/order\u processing\u info.rb中

class Order
 module OrderProcessingInfo
  extend ActiveSupport::Concern

  included do

  end
  ...
end
但是根据正确的方式来定义关注点应该是

1) 将其放入../models/concerns/[FILENAMEHERE]而不是../models/concerns/[CLASSNAMEHERE]/[FILENAMEHERE]

2) 定义模块而不在类中包装它,如下所示:

module OrderProcessingInfo
  extend ActiveSupport::Concern

  included do

  end
end

花了一些时间才弄清真相,但希望这可能会帮助其他人。

看起来有另一个“订单”或“库存订单”类,或者在几个地方定义了它(monkeypatching?)。还要检查您是否已将“负载”设置为“真”。@Roman:是的,应该是这样