2011-09-06 5 views
0

내 프로젝트에서 '범위'를 사용하고 싶습니다.스코프에 상수가 없습니다. 제품입니까?

은 내가 '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] 
    }, 
... 

같은

the directory structure

파일'product.rb '몇 가지 방법을 포함, 내 모델에서 사용 참조 lib 디렉토리 아래의 폴더를 생성 '

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 제품 정의 파일의 이름을 바꾸고 일반 모듈을 사용하는 방법을 알고 있습니다. 그러나 나는 무엇이 '모듈 스코프 :: 제품'인지 이해하고 싶습니다. 어떻게 작동합니까? 소스 코드는 opensource의 'Spree' – ivanLee

2

당신은 당신의 자동로드 DIRS에 lib/scopes를 추가 할 수 있었나요? Ruby가 무언가를 자동로드하려고하지만 이미 정의 된 것을 얻는다면이 메시지를 보게 될 것입니다. 예를 들어, Product에 대한 정의를 얻으려는 경우 lib/scopes/product.rb을로드하면 모두 Scopes::Product이됩니다. 자동로드 메커니즘은 그렇게 영리하지 않고, 일을 해결하거나 나무를 철저히 검색하려고하지 않습니다. 당신을 위해

0

사용 Product::ORDERING 또는 대신 Scopes::Product::ORDERINGProduct::SCOPES 또는 Scopes::Product::SCOPES

관련 문제