Sunday, 26 August 2012

Active admin relationships between models

I have used active admin for my rails application admin section.

I have 2 tables products and category.

Product class

belongs_to :category


Category class

has_many :products



I have created two resources for the above two models in admin folder. Every thing went well and for both the resources its displaying the list view perfectly.

When I try to create the product from product new screen its displaying the categories options as list of all categories objects and not the categories records.

I have made some goggling and came to find solution that we need add the below method in my category class to display the category names in the drop down to choose while creating the product.


In my category class

  def to_s
    category_name
  end


Thank You,
Uma Mahesh.

No comments:

Post a Comment