Search code examples
ruby-on-rails-4activeadminnested-formsbelongs-to

ActiveAdmin belongs_to index show associated field


Trying to show the nested field and not just the ID. eg product_catergory_id instead of showing the foreign key 1 show "Computers" from the product_catergories/product_catergory (table/field id 1). Seems to be a lot of info on f.inputs but not on Columns.

product
belongs_to :product_catergories
(has all the foreign keys)


product_catergories
has_many : products

app/admin/products.rb  --partial  

index do
    selectable_column
    #my stuff here
    column :name
    column :product_description
    column :product_catergory_id
    column :product_colour_id
    column :product_size_id
    column :supplier_id
    actions
  end
Found the solution

 index do
    selectable_column
    #my stuff here
    column :name
    column :product_description
    column :product_catergory_id
    column "product_catergory_id" do |i|
      i.product_catergory.product_catergory
    end
    column :product_colour_id
    column :product_size_id
    column :supplier_id
    actions
  end


Solution

  • index do
        selectable_column
        #my stuff here
        column :name
        column :product_description
        column :product_catergory_id
        column "product_catergory_id" do |i|
          i.product_catergory.product_catergory
        end
        column :product_colour_id
        column :product_size_id
        column :supplier_id
        actions
      end