update...
I have a method that gives me the sum of a column. How do I call this method and show it in a div above the table on the index page?
ActiveAdmin.register Account do
actions :all, :except => [:new]
index do
selectable_column
column :id
column :uid
column :nickname
column :name
column :description
column :listed_count
column :friends_count
column :followers_count
column :created_at
column :updated_at
column :active
actions
end
controller do
def total_followers
Account.sum(:followers_count)
end
end
end
The way you have it, total_followers
is a local variable that will be set at load time of the class and never updated, as you've experienced. The way to fix this would be to make total_followers
into a method, such as:
ActiveAdmin.register Account do
def total_followers
Account.sum(:&followers_count)
end
# ...
end
Then your Accounts summation will be evaluated each time the method is called.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.