Search code examples
ruby-on-railsrubyruby-on-rails-5activeadmin

Active admin custom index with instant method column


i have a user model

class User < ApplicationRecord
has_many :payments, dependent: :destroy
has_many :debts, dependent: :destroy

def balance
@balance = self.payments.sum(:amount) - self.debts.sum(:amount)
end

end

and i have index in user controller

index do 
selectable_column
column :id
column :name
column :identity_card
column :address
column :contact
column :balance
column :code
column :created_at
column :updated_at
actions
end

how to display the balance on the index with my instance method on the user model?


Solution

  •   column 'Balance' do |user|
       user.balance
      end
    

    Documentation