0

我正在使用mongoid-4.0.0.beta1并遵循他们的文档来定义一个scope我得到这个错误:

/usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta1/lib/mongoid/scopable.rb:306:in `check_scope_validity':  (Mongoid::Errors::InvalidScope)
Problem:
  translation missing: pt-BR.mongoid.errors.messages.invalid_scope.message
Summary:
  translation missing: pt-BR.mongoid.errors.messages.invalid_scope.summary
Resolution:
  translation missing: pt-BR.mongoid.errors.messages.invalid_scope.resolution
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta1/lib/mongoid/scopable.rb:90:in `default_scope'
    from /Users/aelesbao/src/getninjas/kitana/app/models/subscription.rb:21:in `<class:Subscription>'
    from /Users/aelesbao/src/getninjas/kitana/app/models/subscription.rb:3:in `<top (required)>'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `block in require'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:330:in `require_or_load'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:463:in `load_missing_constant'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/aelesbao/src/getninjas/kitana/spec/models/subscription_spec.rb:3:in `<top (required)>'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `load'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `block in load'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:223:in `load'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/var/rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

样本:

class Band
  include Mongoid::Document

  field :name, type: String
  field :active, type: Boolean, default: true

  default_scope where(active: true)
end
4

1 回答 1

2

实际上,似乎从 4.0 版本开始,我们需要将 lambda 用于作用域:

class Band
  include Mongoid::Document

  field :name, type: String
  field :active, type: Boolean, default: true

  default_scope -> { where(active: true) }
end
于 2014-06-06T23:18:52.470 回答