Module: ActiveAdmin::ScopeChain

Included in:
ResourceController::Collection::Scoping, Views::Scopes
Defined in:
lib/active_admin/helpers/scope_chain.rb

Instance Method Summary collapse

Instance Method Details

#scope_chain(scope, chain) ⇒ ActiveRecord::Relation or ActiveRecord::Base

Scope an ActiveRecord::Relation chain

Example:

scope_chain(Scope.new(:published), Article)
# => Article.published

Parameters:

  • scope

    The <ActiveAdmin::Scope> we want to scope on

  • chain

    The ActiveRecord::Relation chain or ActiveRecord::Base class to scope

Returns:

  • (ActiveRecord::Relation or ActiveRecord::Base)

    The scoped relation chain



13
14
15
16
17
18
19
20
21
# File 'lib/active_admin/helpers/scope_chain.rb', line 13

def scope_chain(scope, chain)
  if scope.scope_method
    chain.send(scope.scope_method)
  elsif scope.scope_block
    instance_exec chain, &scope.scope_block
  else
    chain
  end
end