Scopes is not missing constant Product?
I want to use 'scope' in my project.
i create a folder under lib, see
The file 'product.rb' include some methods, like
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'
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? You will get this message if Ruby is trying to autoload something but gets something that is already defined. For example, if it tries to get a definition for Product
, loads lib/scopes/product.rb
and all it gets is 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
use Product::ORDERING
or Product::SCOPES
instead of Scopes::Product::ORDERING
or Scopes::Product::SCOPES
精彩评论