Rails 3.0 で書かれた大きなプロジェクトがあります。
そのプロジェクトの最大のモデルがQuestinaryです。すべての典型的なモデルとして ActiveRecord::Base から継承されます。そのモデルの多くの部分は、Questionary から継承された個別のモデルに取り出されました。
そのようなモデルのスコープに問題があります。問題は、ActiveRecord がスコープを理解せず、Proc を使用することです。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 が良くないことは知っていますが、アプリケーションが壊れるので更新できません。
約 1 年前、それはうまく機能していましたが、その後サーバーが分解されました。今、私はそれを生き返らせる必要があります。
更新:
スコープの例:
default_scope proc { where(:status => "reviewed") }