forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 4
How to add instance methods for the dashboard
jpmckinney edited this page Jun 29, 2012
·
5 revisions
The default dashboard has this example in the code comments:
# == Conditionally Display
# Provide a method name or Proc object to conditionally render a section at run time.
#
# section "Membership Summary", :if => :memberships_enabled?
but where do you define :memberships_enabled?
?
You can't get access to the dashboard controller by doing:
ActiveAdmin::Dashboards.build do
controller do
def memberships_enabled?
true
end
end
end
because Dashboard doesn't inherit from DSL like pages and resources do.
This doesn't work either:
ActiveAdmin::Dashboards.build do
def memberships_enabled?
true
end
section "Membership Summary", :if => :memberships_enabled?
end
Instead, you have to add the method to the dashboard controller directly:
class Admin::DashboardController
def memberships_enabled?
true
end
end
where Admin
is your namespace. Note: You may encounter errors about the namespace being undefined. In that case, you may want to defined your helper methods directly on the base dashboard controller class, ActiveAdmin::Dashboards::DashboardController
.