ruby on rails - Active Record callbacks throw "undefined method" error in production with classes using STI -


i have many instances in application use single table inheritance , works fine in development environment. when release production (using passenger) following error:

undefined method `before_save' inventoryorder:class (nomethoderror)

why work in dev environment , not work in production? both using rails 4.2 , ruby 2.1.5. problem passenger?

here inventoryorder class:

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 |op|             if !producttypes::is_mix?(op.product_type.type)                 raise exceptions::failedvalidations, _("can't have inventory order 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} #{amount_free} left"})             end         end      end      def self.create_replenishment_order(product_type_id, amount)          # first check current inventory orders         orders = inventoryorder.joins(:order_products).where("order_products.product_type_id = ? , status <> ? , 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 #{order_product.amount}kg of #{order_product.product_type.name} cancelled after feed mill job started."         })     end  end 

and here it's parent class:

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 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 client"))     end    end   ...  end 

thanks, eric

after doing more digging , of roman's comment able figure out issue result of me using older convention activerecord::concerns works fine on windows not on unix based systems.

according this railscasts can define concerns this:

in ../models/concerns/order/order_processing_info.rb

class order  module orderprocessinginfo   extend activesupport::concern    included    end   ... end 

but according this right way define concern to

1) put in ../models/concerns/[filenamehere] instead of ../models/concerns/[classnamehere]/[filenamehere]

2) define module without wrapping in class this:

module orderprocessinginfo   extend activesupport::concern    included    end end 

took digging bottom of might else out there.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -