Search code examples
ruby-on-railsactiveadminruby-on-rails-7

ActiveAdmin: render index table of has many resource in show page of parent


Trying to build this with Active admin 3.0. This seems so basic to me that I feel I must be missing something.

Let's assume I have a Store model and an Employee model and a store has many employees and employees belong to a store.

When I go to the show page for a store, I would like, below the main section of store attributes, to have a table that lists all the employees for that store. I would literally just like to render the employees index as a partial or something like that and that pass it the employees for that specific store.

I don't want to custom code all of this and end up having to rewrite all the index logic and related styling and html, it seems like there should be a simpler way. Is there some one liner I can throw in?


Solution

  • I hope this will help you)

    ActiveAdmin.register Store do
    
      # other code...
    
      show do
        attributes_table do
          row :id
          row :name
          row :description
          # other rows for Store model...
        end
    
        panel 'Employees' do
          paginated_collection(store.employees.page(params[:page]).per(15), download_links: false) do
            table_for(collection, sortable: false) do
              column :id
              column :username
              # Other columns for the Employees table
            end
          end
        end
      end
    
      # other code...
    
    end