关联时提出的“没有接收者”的例外情况

时间:2014-08-28 07:05:48

标签: ruby-on-rails-4 deprecation-warning

user.recipes.count抛出异常“没有给出接收者”。食谱协会的每一项操作都是这样做的(第一次,最后一次,总和......)。

没有发生宝石更新。

这里是Callstack:

activerecord (4.0.3) lib/active_record/relation/spawn_methods.rb:41:in `instance_exec'
activerecord (4.0.3) lib/active_record/relation/spawn_methods.rb:41:in `merge!'
activerecord (4.0.3) lib/active_record/relation/spawn_methods.rb:33:in `merge'
activerecord (4.0.3) lib/active_record/scoping/default.rb:115:in `block (2 levels) in build_default_scope'
activerecord (4.0.3) lib/active_record/scoping/default.rb:111:in `each'
activerecord (4.0.3) lib/active_record/scoping/default.rb:111:in `inject'
activerecord (4.0.3) lib/active_record/scoping/default.rb:111:in `block in build_default_scope'
activerecord (4.0.3) lib/active_record/scoping/default.rb:138:in `evaluate_default_scope'
activerecord (4.0.3) lib/active_record/scoping/default.rb:110:in `build_default_scope'
activerecord (4.0.3) lib/active_record/relation.rb:554:in `with_default_scope'
activerecord (4.0.3) lib/active_record/relation/finder_methods.rb:324:in `find_first'
activerecord (4.0.3) lib/active_record/relation/finder_methods.rb:90:in `first'
activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:129:in `first'
activerecord (4.0.3) lib/active_record/associations/collection_association.rb:602:in `first_or_last'
activerecord (4.0.3) lib/active_record/associations/collection_association.rb:103:in `first'
activerecord (4.0.3) lib/active_record/associations/collection_proxy.rb:171:in `first'
app/views/users/_index.html.erb:26:in `block in _app_views_users__index_html_erb__4515165452254072945_70190748446560'
activerecord (4.0.3) lib/active_record/relation/delegation.rb:13:in `each'
activerecord (4.0.3) lib/active_record/relation/delegation.rb:13:in `each'
app/views/users/_index.html.erb:20:in `_app_views_users__index_html_erb__4515165452254072945_70190748446560'
(standard part following omitted)

1 个答案:

答案 0 :(得分:-1)

观看日志。有一个弃用警告:

DEPRECATION WARNING: Calling #default_scope without a block is deprecated. 
For example instead of `default_scope where(color: 'red')`, please use `default_scope { where(color: 'red') }`. 
(Alternatively you can just redefine self.default_scope.). (called from ...)

修复它修复了异常。