首页 > 解决方案 > Rails 能够在开发中解析命名空间模型,但不能在暂存环境中解析

问题描述

我在暂存时遇到以下错误,但在本地工作正常。

NameError (uninitialized constant Manager::Seller::Product)

导致错误的行/app/services/manager/admins/sellers/products/curation.rb

module Manager
  module Admins
    module Sellers
      module Products
         class Curation
            ...
            def my_function
               @product.update(entity_id: @entity_id,
                               curation_status: Seller::Product.curation_statuses[:accepted])
             end
      ....

::它在通过附加到上面的代码中使其成为绝对时起作用Seller::Product,以便它将从目录顶部解析它。

奇怪的事情:在我的本地/开发环境中,我没有收到错误。

我是在正确地做名称间距/常量的事情还是

型号/卖家/product.rb

  class Seller::Product < ApplicationRecord
      ...
  end
end

模型/seller.rb

class Seller < ActiveRecord::Base
   ...
end

参考:http : //guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoload-paths-and-eager-load-paths

标签: ruby-on-railsrubyruby-on-rails-5

解决方案


推荐阅读