valid_scope_name?':私有方法“警告”;更新到活动记录 3.1 (rails) 时调用 nil:NilClass (NoMethodError) 异常
问题是有一个 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 中止!
我搜索了类似的错误,但什么也没找到(主要是痕迹的糊状)。有谁知道可能是什么问题?
先感谢您。 干杯, 内森
The thing is there is a rubygem which adds some syntactic sugar to RoR ActiveRecord for defining filters and orders. We were using meta_where, then switched to squeel to get rails 3 support.
The thing is that everything worked fine with ActiveRecord <= 3.0.10, now when I tried to switch to 3.1.0 in the gem I'm getting this error:
/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)
The whole trace is as follows:
/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!
I searched for similar errors but found nothing (mostly pasties of traces). Does anyone knows what might be the problem?
Thank you in advance.
Cheers,
Neithan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重新加载模型时的行为已更改。虽然 3.0 懒得加载'app/models/post.rb' 3.1 会抛出此错误。
当您喜欢在控制台上以交互方式优化模型时,您必须先使用
Object.send :remove_const, 'Post'
删除模型。The behaviour when reloading models has changed. While 3.0 doesn't bother to
load 'app/models/post.rb'
3.1 throws this error.When you love to interactively refine your models on the console, you have to delete the model with
Object.send :remove_const, 'Post'
before.我设法修复它。
结果发现问题出在测试套件中。由于这个 gem 是为了添加一些语法糖来定义过滤器和命令,所以它干扰了 ActiveRecord。
显然,在删除一切正常之后,在重新评估类或在测试用例中具有相同名称的类时,这样做会导致问题。
I managed to fix it.
It turned out the problem was in the test suite. Since this gem was about adding some syntactic sugar for defining filters and orders it interfered int the ActiveRecord.
Apparently doing so causes problem while reevaluating classes or having classes with the same names in test cases, after removing that everything worked.