I have big project written on Rails 3.0.
Biggest model of that project is Questinary. It's inherited from ActiveRecord::Base as all typical models. Many parts of that model taked out into separate models inherited from Questionary.
I have a problem with scopes in such models. Problem is ActiveRecord didn't understand scopes then they use Procs. Scopes with Procs into Questinary model itself works fine. Also all fine then scope didn't contain Proc.
Error message is undefined method 'includes_values' for #<Proc:0x000000081cde98>
Backtrace:
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'
As you can see ActiveRecord called from the ActiveAdmin, so problem can be related to it.
Rails version: 3.0.20
ActiveAdmin version: 0.3.4
I know about old gem versions is not good, but I can't update them because it will broke application.
About year ago that stuff working well but then servers was disassembled. Now I need to reanimate it.
UPDATE:
Scope example:
default_scope proc { where(:status => "reviewed") }
It was problem with default_scope written as:
default_scope proc { where(:status => "reviewed") }
It wasn't possible for me to just remove proc (i.e. default_scope where(:status => "reviewed")
. Because in that case ActiveRecord trying to access database, but database in my application available not all the time.
So I need kind of lazy way to use default_scope.
@andrey's suggestion (scope :default_scope, lambda { where(:status => "reviewed") }
) do not fit because involve changes in all code that calling default scope.
I tried to use block instead of proc (i.e. default_scope { where(:status => "reviewed") }
) but in Rails 3.0 I haven't success.
So I define default_scope as class method like this:
def self.default_scope
where(:status => "reviewed")
end
That works exactly as I need.