简体   繁体   English

范围不缺少恒积?

[英]Scopes is not missing constant Product?

I want to use 'scope' in my project. 我想在项目中使用“范围”。

i create a folder under lib, see 我在lib下创建一个文件夹,请参见

目录结构

The file 'product.rb' include some methods, like 文件“ product.rb”包含一些方法,例如

module Scopes::Product
  #TODO: change this to array pairs so we preserve order?

  SCOPES = {
    # Scopes for selecting products based on taxon
    :taxon => {
      :taxons_name_eq => [:taxon_name],
      :in_taxons => [:taxon_names],
    },
    # product selection based on name, or search
    :search => {
      :in_name => [:words],
      :in_name_or_keywords => [:words],
      :in_name_or_description => [:words],
      :with_ids => [:ids]
    },
...

I use it in my model 'product.rb' 我在模型“ product.rb”中使用它

include ::Scopes::Product

error message: 错误信息:

pry(main)> Product
ArgumentError: Scopes is not missing constant Product!
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:479:in `load_missing_constant'

Did you happen to add lib/scopes to your autoload dirs? 您是否碰巧将lib/scopes添加到了自动加载目录? You will get this message if Ruby is trying to autoload something but gets something that is already defined. 如果Ruby尝试自动加载某些内容但获取已经定义的内容,则会收到此消息。 For example, if it tries to get a definition for Product , loads lib/scopes/product.rb and all it gets is Scopes::Product . 例如,如果尝试获取Product的定义,则加载lib/scopes/product.rb ,而得到的只是Scopes::Product The autoload mechanism is not so clever, it doesn't try to resolve things or exhaustively search the trees. 自动加载机制不是很聪明,它不会尝试解决问题或详尽搜索树。

Please try namespacing this way.. 请尝试以这种方式命名。

module Scopes
  module Product
      ....
  end
end

使用Product::ORDERINGProduct::SCOPES代替Scopes::Product::ORDERINGScopes::Product::SCOPES

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM