I have an issue with a dynamic active admin scope. I am attempting to create a scope for each \"manager\" of a \"project\" in my app. However, the scopes don\'t seem to up
Here is my optimized solution based on Brant Sterling Wedel's answer.
This solution contains the following additional enhancements:
### Default scope must be set in advance
scope "Jeff", default: true do |x|
x.joins(:manager).where(manager: {name: "Jeff"})
end
controller do
before_action :reload_scopes, only: :index
def reload_scopes
resource_config = active_admin_config
resource_config.instance_variable_set(:@scopes, [
resource_config.scopes.first ### Default scope
])
Manager.all.each do |m|
next if resource_config.scopes.first.name == m.name
resource_config.scopes << ActiveAdmin::Scope.new(m.name){|scope| scope.where(manager_id: m.id) }
end
end
end