Pujan Soni
Pujan Soni

Reputation: 165

How to display the nested attributes in the index action in active admin

My activeadmin club resource file is: clubs.rb

ActiveAdmin.register Club do
  permit_params :name, :email, :admin_id,
club_profile_attributes: [
  :id, :club_id, :logo, :address_1, :address_2, :city,
  :state, :country_id, :latitude, :longitude, :website, :email,
  :fiscal_number, :phone_number_1, :phone_number_2]
  index do
    selectable_column
    column :id
    column :name
    column :admin
    column :created_at
    column :updated_at
    actions
  end

I want to display the club profile attributes in my above file in the index action. The relationship is: club has_one :club_profile

Upvotes: 1

Views: 833

Answers (1)

arieljuod
arieljuod

Reputation: 15838

What (all the attributes? only some?) and how (one for each column? everything on the same column?) do you want to show?

Check the docs https://activeadmin.info/3-index-pages/index-as-table.html

If you add column: :club_profile, ActiveAdmin will try some methods to retrieve the value in this order: :display_name, :full_name, :name, :username, :login, :title, :email, :to_s

If you want to specify how to retrieve the value, you can pass a block:

index do
  selectable_column
  column "Profile logo" do |club|
    image_tag club.club_profile.logo
  end
end

If you want multiple columns then I guess you'll have to use a custom block for each column.

Upvotes: 1

Related Questions