Module: ActiveAdmin::ResourceController::Collection::Scoping

Included in:
ActiveAdmin::ResourceController::Collection
Defined in:
lib/active_admin/resource_controller/collection.rb

Instance Method Summary collapse

Instance Method Details

#active_admin_collectionObject (protected)



85
86
87
# File 'lib/active_admin/resource_controller/collection.rb', line 85

def active_admin_collection
  scope_collection(super)
end

#current_scopeObject (protected)



106
107
108
109
110
111
112
# File 'lib/active_admin/resource_controller/collection.rb', line 106

def current_scope
  @current_scope ||= if params[:scope]
    active_admin_config.get_scope_by_id(params[:scope]) if params[:scope]
  else
    active_admin_config.default_scope
  end
end

#scope_collection(chain) ⇒ Object (protected)



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/active_admin/resource_controller/collection.rb', line 89

def scope_collection(chain)
  if current_scope
    @before_scope_collection = chain

    # ActiveRecord::Base isn't a relation, so let's help you out
    return chain if current_scope.scope_method == :all

    if current_scope.scope_method
      chain.send(current_scope.scope_method)
    else
      instance_exec chain, &current_scope.scope_block
    end
  else
    chain
  end
end