4

我有两个这样的模型:

class Kid < ActiveRecord::Base
  belongs_to :sex
  attr_accessible :name
end

class Sex < ActiveRecord::Base
  attr_accessible :description
  has_many :kids
end

但是对于我的生活,我无法弄清楚如何让关联出现在管理员中。当我去编辑一个孩子时,我看到一个性别标签,但没有下拉菜单,也没有任何提示 RailsAdmin 看到该关联。它只在下面显示标签名称、空格和“可选”一词。

我一遍又一遍地搜索dox,但我找不到解决方案。我是菜鸟,所以有可能我看过它,应该受到嘲笑。

我没有修改任何其他管理代码。

4

2 回答 2

8

该关系在 Kid 中应该是可访问的,尝试将 sex_id 添加到可访问的属性中。

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

于 2012-07-16T22:28:03.987 回答
0

感谢 Gaël Marziou,我想出了如何与中间模型(与 has_many :through... 关联使用的模型)“连接”,如下所示:

class CategoryPets < ActiveRecord::Base
  belongs_to :category
  belongs_to :pet

  attr_accessible :category_id, :pet_id
end
于 2013-05-22T21:35:36.430 回答