forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 4
Creating dynamic scopes
amalagaura edited this page Dec 5, 2011
·
4 revisions
We can create dynamic scopes which are defined at initialization time (so not completely dynamic in production, the initializer will only be loaded at startup).
Here is an example where item_types are a category table and items belong to item_type through the item_type_id.
ActiveAdmin.register Item do
scope :all, :default => true
ItemType.all.each do |item_type|
self.send(:scope, item_type.name) do |items|
items.where(:item_type_id => item_type.id)
end
end
end