2011-09-06 27 views
0

我想在我的项目中使用'范围'。示波器不缺少恒定的产品?

我创建lib下的文件夹,看到

the directory structure

文件 '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] 
    }, 
... 

我用它在我的模型“product.rb '

include ::Scopes::Product 

错误消息:

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' 

回答

1

请重命名空间这样..

module Scopes 
    module Product 
     .... 
    end 
end 
+0

感谢您的答复,但它不能正常工作。请参阅新的错误LoadError:Expected /home/tanglin/fincloud/lib/scopes/product.rb来定义产品我知道一种方法来使它工作,只是为了更改文件的名称,并使用普通模块。但是我想明白'模块范围::产品'是什么意思,它是如何工作的?源代码来自开源“Spree” – ivanLee

2

你碰巧添加你自动加载迪尔斯?如果Ruby尝试自动加载某些内容但获取已定义的内容,则会收到此消息。例如,如果它试图获得Product的定义,则加载lib/scopes/product.rb,它的全部值为Scopes::Product。自动加载机制并不那么聪明,它不会试图解决问题或彻底搜索树木。

0

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