valid_scope_name?':私有方法`warn'在更新到活动记录3.1(rails)时调用nil:NilClass(NoMethodError)异常

时间:2011-09-16 14:40:58

标签: ruby-on-rails-3 activerecord rubygems squeel

事情是有一个rubygem为RoR ActiveRecord添加一些语法糖来定义过滤器和订单。我们使用meta_where,然后切换到squeel以获得rails 3支持。 问题是ActiveRecord< = 3.0.10一切正常,现在当我试图在gem中切换到3.1.0时我遇到了这个错误:

/Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activerecord-3.1.0/lib/active_record/named_scope.rb:194:in `valid_scope_name?': private method `warn' called for nil:NilClass (NoMethodError)

整个痕迹如下:

/Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activerecord-3.1.0/lib/active_record/named_scope.rb:194:in `valid_scope_name?': private method `warn' called for nil:NilClass (NoMethodError)
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activerecord-3.1.0/lib/active_record/named_scope.rb:175:in `scope'
    from ./test/simplificator_filter/filterable/filterable_test.rb:12
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@filters/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
    from /Users/admin/.rvm/gems/ree-1.8.7-2011.03@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5

rake aborted!

我搜索了类似的错误,但没有发现任何东西(主要是痕迹的馅饼)。有谁知道可能是什么问题?

提前谢谢你。 干杯, Neithan

2 个答案:

答案 0 :(得分:1)

重新加载模型时的行为已更改。虽然3.0不打扰load 'app/models/post.rb' 3.1抛出此错误。 如果您喜欢在控制台上以交互方式优化模型,则必须先使用Object.send :remove_const, 'Post'删除模型。

答案 1 :(得分:0)

我设法解决了这个问题。

事实证明问题出在测试套件中。由于这个gem是关于添加一些语法糖来定义过滤器和命令,它干扰了ActiveRecord。

显然这样做会在重新评估类或在测试用例中具有相同名称的类之后导致问题,在删除所有工作之后。