我有一个在 Rails 3.0 上编写的大项目。
该项目的最大模型是Questinary。它继承自 ActiveRecord::Base 作为所有典型模型。该模型的许多部分被提取到从 Questionary 继承的单独模型中。
我对此类模型中的范围有疑问。问题是 ActiveRecord 不了解范围,然后他们使用 Procs。带有 Procs 的范围进入 Questinary 模型本身可以正常工作。一切都很好,然后范围不包含 Proc。
错误信息是undefined method 'includes_values' for #<Proc:0x000000081cde98>
回溯:
activerecord (3.0.20) lib/active_record/relation/spawn_methods.rb:11:in `block in merge'
activerecord (3.0.20) lib/active_record/relation/spawn_methods.rb:10:in `each'
activerecord (3.0.20) lib/active_record/relation/spawn_methods.rb:10:in `merge'
activerecord (3.0.20) lib/active_record/named_scope.rb:32:in `scoped'
activerecord (3.0.20) lib/active_record/base.rb:449:in `rescue in order'
activerecord (3.0.20) lib/active_record/base.rb:447:in `order'
/home/sergey/.rvm/gems/ruby-1.9.3-p484/bundler/gems/active_admin-534e909fe7dc/lib/active_admin/resource_controller/collection.rb:51:in `sort_order'
/home/sergey/.rvm/gems/ruby-1.9.3-p484/bundler/gems/active_admin-534e909fe7dc/lib/active_admin/resource_controller/collection.rb:44:in `active_admin_collection'
/home/sergey/.rvm/gems/ruby-1.9.3-p484/bundler/gems/active_admin-534e909fe7dc/lib/active_admin/resource_controller/collection.rb:63:in `active_admin_collection'
/home/sergey/.rvm/gems/ruby-1.9.3-p484/bundler/gems/active_admin-534e909fe7dc/lib/active_admin/resource_controller/collection.rb:86:in `active_admin_collection'
/home/sergey/.rvm/gems/ruby-1.9.3-p484/bundler/gems/active_admin-534e909fe7dc/lib/active_admin/resource_controller/collection.rb:114:in `active_admin_collection'
/home/sergey/.rvm/gems/ruby-1.9.3-p484/bundler/gems/active_admin-534e909fe7dc/lib/active_admin/resource_controller/collection.rb:17:in `collection'
inherited_resources (1.2.2) lib/inherited_resources/actions.rb:7:in `index'
/home/sergey/.rvm/gems/ruby-1.9.3-p484/bundler/gems/active_admin-534e909fe7dc/lib/active_admin/resource_controller/actions.rb:11:in `index'
app/admin/questionary_scope_uni_groups.rb:216:in `index'
如您所见,从 ActiveAdmin 调用 ActiveRecord,因此问题可能与此有关。
Rails version: 3.0.20
ActiveAdmin version: 0.3.4
我知道旧的 gem 版本不好,但我不能更新它们,因为它会破坏应用程序。
大约一年前,这些东西运行良好,但后来服务器被拆解了。现在我需要重新激活它。
更新:
范围示例:
default_scope proc { where(:status => "reviewed") }