Unable to define associations in Rails_Admin

I have two models:

class Kid < ActiveRecord::Base belongs_to :sex attr_accessible :name end class Sex < ActiveRecord::Base attr_accessible :description has_many :kids end 

But for my life I can’t understand how to make the association appear in the admin. When I move on to editing the child, I see a shortcut for sex, but there is no drop-down list, there is no hint that RailsAdmin sees the connection. It just shows the label name, space and the word “optional” below.

I looked through dox again and again, but I cannot find a solution. I am noob, so maybe I looked right above him and should be ridiculed.

I have not modified any other admin code yet.

+4
source share
2 answers

The relationship should be available in Kid, try adding sex_id to the available attributes.

 class Kid < ActiveRecord::Base belongs_to :sex attr_accessible :name, :sex_id end 
+7
source

Thanks to Gaël Marziou, I figured out how to “connect” to an intermediate model (the one used with has_many: through ... association) as follows:

 class CategoryPets < ActiveRecord::Base belongs_to :category belongs_to :pet attr_accessible :category_id, :pet_id end 
0
source

All Articles