2011-09-06 28 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